Results 1 to 5 of 5
  1. #1
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480

    Excel Question, Hoping someone can give me some advice to save me some time.


    I am wanting to make a macro in excel, I have around 40 cells that need to be copied and pasted into other cells across 9 worksheets. Is there a way to dim all of these cells once so I can use them later? I will have to do individual cells, and worksheets.

    An example of what I am trying to do, keep getting error 1004

    Sub Test()
    Dim VName As String
    VName = Range("B:21").Value
    End Sub

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    VName = Range("B:21").Value
    You have a syntax error there. If you want the value from cell B21, it should look like:
    VName = Range("B21").Value

  3. #3
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Wow, thank you.
    So now that I have everything setup, how do I paste into another cell on another sheet?

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    A few ways to go about that.

    You could do it like this:
    Code:
    Sheets("Sheet2").Range("A1") = VName
    Or you could even bypass the need for a "VName" variable altogether, and use something like this:
    Code:
    Sheets("Sheet2").Range("A1") = Sheets("Sheet1").Range("B21")

  5. #5
    ipisors is offline Access Developer
    Windows XP Access 2007
    Join Date
    Sep 2013
    Posts
    119
    You should declare workbook, worksheet and range variables or at least worksheet. Never use Excel vba without explicitly referring to objects.

    Example:

    Code:
    dim ws1 as Worksheet
    dim ws2 as Worksheet
    set ws1=ThisWorkbook.Worksheets("Name of Worksheet")
    set ws2=ThisWorkbook.Worksheets("Name of Another Worksheet")
    ws2.Range("B21").Value = ws1.Range("B21").Value '(or whatever you want to do)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 02-03-2014, 03:06 AM
  2. Hoping someone can save me a ton of time.
    By redbull in forum Access
    Replies: 2
    Last Post: 10-30-2013, 10:45 PM
  3. Replies: 1
    Last Post: 09-21-2013, 10:42 PM
  4. how to give a code for save and refresh
    By venu_resoju in forum Forms
    Replies: 7
    Last Post: 04-03-2013, 12:29 PM
  5. Replies: 19
    Last Post: 12-02-2012, 07:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums