+ Reply to Thread
Results 1 to 9 of 9

implement variable increment in VB Code

Hybrid View

  1. #1
    Registered User
    Join Date
    09-20-2016
    Location
    Bangalore
    MS-Off Ver
    2013
    Posts
    32

    implement variable increment in VB Code

    Kindly assist me to complete the below task using macros.

    In the Given file, columns B,C,D are variables and the data has to be pasted side by side as the date changes. So i just need to copy the data present in col B,C,D and paste in the E,F,G columns. when i run the macro for second time the data at that instant has to be placed in the H,I,J column and so on. Also i need to fetch the date from another sheet as shown
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: implement variable increment in VB Code

    Does this help?

    Sub invendis()
    Dim x As Long
    x = Range("A3").End(xlToRight).Column + 1
    Range("B3:D7").Copy Cells(3, x)
    End Sub

  3. #3
    Registered User
    Join Date
    09-20-2016
    Location
    Bangalore
    MS-Off Ver
    2013
    Posts
    32

    Re: implement variable increment in VB Code

    Hi John,

    i tried and its working perfect.could you please tell me what are the coordinates i need to change to change the number of columns to copy. And i need to paste special only the values in the destination and what is the code to be edited to do so. Could you please help regarding this?

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: implement variable increment in VB Code

    The number of columns is determined by your range you want too copy. The x variable only offsets to the first empty column to paste in. Try this code for values only.

    Sub invendis()
    Dim x As Long
    x = Range("A3").End(xlToRight).Column + 1
    Range("B3:D7").Copy
    Cells(3, x).PasteSpecial xlPasteValues
    End Sub

  5. #5
    Registered User
    Join Date
    09-20-2016
    Location
    Bangalore
    MS-Off Ver
    2013
    Posts
    32

    Re: implement variable increment in VB Code

    Hi John,

    The given code works only for the active sheet. Can we specify the sheet name in the code since i have multiple sheets and multiple codes to be merged

  6. #6
    Registered User
    Join Date
    09-20-2016
    Location
    Bangalore
    MS-Off Ver
    2013
    Posts
    32

    Re: implement variable increment in VB Code

    Hi John,

    Awaiting for your reply

  7. #7
    Registered User
    Join Date
    09-20-2016
    Location
    Bangalore
    MS-Off Ver
    2013
    Posts
    32

    Re: implement variable increment in VB Code

    someone guide me to complete the below task which is given in the attachment

    can we declare the source data to copy as variable by code?

    1. number of rows will be keep on increasing and so need to declare as non blank values as the last cell by only defining the start point.(B3: ~) whereas now we have defined as (B3:D7). The columns will remain same but the rows to be defined as variables.

    2. i need to copy and paste special multiple columns adjacent to it. For example in the file shared by me previously, i need to copy the D3:D7 and paste special in Column H3:H7 and proceeding from that need to copy the B3:B7 column and to be pasted in I3:I7 column.

    please guide me in completing the above task.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    09-20-2016
    Location
    Bangalore
    MS-Off Ver
    2013
    Posts
    32

    Re: implement variable increment in VB Code

    Hello Everyone,

    please let me know the possibility on this process

  9. #9
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: implement variable increment in VB Code

    Try:

    Sub invendis()
    Dim x As Long, ws As Worksheet, y As Long
    For Each ws In ActiveWorkbook.Worksheets
        Select Case ws.Name
            Case Is = "data" ', "Your Second Sheet", "ect" You can put the worksheets here
                x = ws.Range("A3").End(xlToRight).Column + 1
                y = ws.Range("A" & Rows.Count).End(3).row
                Cells(3, 2).Resize(y, 3).Copy
                Cells(3, x).PasteSpecial xlPasteValues
        End Select
    Next ws
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. vba code to increment item sold on a popularity column with 3 variable
    By chubbychub in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-23-2016, 11:28 PM
  2. Replies: 10
    Last Post: 03-07-2014, 08:58 PM
  3. How to implement vlookup in my code.
    By christhweatt in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-11-2013, 05:30 PM
  4. Trying to implement a Global Variable in VBA
    By adam2742 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-18-2013, 02:08 AM
  5. Help: formula or VB code to implement voting system code
    By cdsc in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-24-2013, 01:23 AM
  6. Excel 2007 : How I implement a code?
    By marianmix in forum Excel General
    Replies: 12
    Last Post: 02-28-2011, 06:55 PM
  7. How would I implement this cell increment?
    By Kia in forum Excel General
    Replies: 3
    Last Post: 01-03-2006, 08:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1