Hi,
I'm a new user of VBA and I've run into 3 issues. I'm trying to select states and counties, and based on this selection there will be a set of data for each individual state/county combination that I need to copy and paste into blank rows. In order to display the data I need to plug the number for each state (1, 2, 3, ..., 50) and for each county (1, 2, 3, ... , unknown number) into cells "E5" for state and "F5" for county. I have a table where I can grab these state/county number combinations. However, I run into the following issues:
1. I need to copy the selection from the loop (i.e. 1 for state and 1 for county) and paste the (1, 1) into cells E5 and F5 so that data will be displayed based on this combination. Must be done for each single combination. I haven't been able to do it.
2. Once the data is displayed, I copy the data and I need to paste it on a specific row below. The trick is that the new data must be pasted below to the previous state/county combo data. Let's say that I run combo (1, 1) and I just run combo (1, 2). The data from (1, 2) must be copied below the (1, 1) data. I must keep the data for all different combinations.
3. I want the macro to not copy and paste anything if there's no data displayed and go to the next state/county combo.
This is my code so far:
Sub CopyAndPaste()
Dim StateCounty As Range
Dim Row As Range
Dim Cell As Range
Set StateCounty = Range("XFC279:XFD3475") 'Table of state/county combo.
For Each Row In StateCounty.Rows
For Each Cell In Row.Cells
Range("G168").Select
Range("G168:G258").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("A277").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
Next Cell
Next Row
End Sub
Any help would be greatly appreciated.
Thanks
Miguel
Bookmarks