Copy Variables to next available row

whudson1980

New Member
Joined
Dec 10, 2013
Messages
13
OK, first off, I just want to say that I am kinda proud that I answered someones question here on the forum, to give back a little. And I was proud that I, as an amateur was actually able to help. lol. OK, moving on to the question:

I have a VBA code that asks for several variables. 3 to be exact. Lets call them variable1, variable2, and variable3. All attained through input boxes.

Then there's a sheet ( lets call it Incident Numbers ) that has a list of numbers from A10:A50

I need code to:

Go to Sheet called "Lists" , find the next available row, and copy Sheets("Incident Numbers").Cells("A:10") to column A, variable1 to columnB, variable2 to columnC, etc.
then do the same for Incident Numbers A:11. . . A:12. . .etc. . . and then stop when the range in Incident Numbers column A is blank.

So if Sheets("Incidents:) has column A as :

564
68
65
56
6
8
98

Then Sheets("Lists") should look like:

564 variable1 variable2 variable3
68 varaible1. . .etc.



Any ideas?

So, just to be clear
 
Last edited:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
If i've understood:

Test on a copy of your data as I've not been able to test

Code:
Sub CopyOver()
    Dim wsFrom As Worksheet, wsTo As Worksheet
    
    Dim c As Range
    
    Dim nr As Long ' next row
    
    Set wsFrom = Sheets("Incident Numbers")
    Set wsTo = Sheets("Lists")
    
    nr = wsTo.Range("A" & Rows.Count).End(xlUp).Row + 1
    
    For Each c In wsFrom.Range("A10:A50")
        If c <> "" Then
            
            wsTo.Range("A" & nr) = c
            wsTo.Range("B" & nr) = variable1
            wsTo.Range("C" & nr) = variable2
            wsTo.Range("D" & nr) = variable3
            
            nr = nr + 1
        End If
    Next c
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top