For each c, find column

jrepko11

New Member
Joined
Nov 10, 2011
Messages
25
Hello,

I am going through a range of cells down column A, then going across the row of that cell to determine the value inputed by user. If c.value > 0, I will copy and paste specific cells to another sheet. See code portion below:

Dim TargetCell As Range
Set TargetCell = Range("A6")

Dim LastCell As Range
Set LastCell = Range("A65536").End(xlUp).Offset(-1, 0)

Dim NameCell As Range
Set NameCell = Range("C2")

Dim SrvGrpCell As Range
Set SrvGrpCell = Range("L2")

For Each cat In Range(TargetCell, LastCell)
For Each c In Range(cat.Offset(0, 1), cat.Offset(0, 7))

If c.Value > 0 Then

'This just creates a separate worksheet if it's not already created. Don't need help here

If WorksheetExists("Data") = False Then
'Create data sheet with headers
ActiveWorkbook.Worksheets.Add(After:=Sheets(Sheets.Count)).Name = "Data"
Sheets("Data").Select
ActiveCell.FormulaR1C1 = "Name"
Range("B1").Select
Range("C1").Select
ActiveCell.FormulaR1C1 = "Category"
Range("D1").Select
ActiveCell.FormulaR1C1 = "Date"
Range("E1").Select
ActiveCell.FormulaR1C1 = "Hours"
Range("C2").Select
Else
End If

NameCell.Copy
Worksheets("Data").Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
SrvGrpCell.Copy
Worksheets("Data").Range("B65536").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
cat.Copy
Worksheets("Data").Range("C65536").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
End If
Next c
Next cat
.....

Column.c.Copy?

Here is where I have an issue. The three individual cells that are being copied above (NamceCell, SrvGrpCell, and cat) are all defined and copying fine. I now want to copy the cell that is in row 5 of the same column (which changes with each c). Is there any way to copy "Column.c" or something of the sort?

Any help is appreciated, thanks!!!!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Can anyone help? My other thought was to have an "offset of an offset"?

ex:

c.Offset(.End(xlUp).Offset(-5, 0), 0).Copy

I need the cell in the 5th row of the sheet, in column c (which changes with each loop)

Anything is appreciated, thanks!
 
Upvote 0
Hi

Are you aware of the syntax shown below? Can be helpful.

Code:
Sub Info()

Sheets("Sheet1").Cells(5, 3).Value = 10
' attributes 10 to cell C5 => fifth row, third column
' alter the row and column index as you like

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,110
Messages
6,123,146
Members
449,098
Latest member
Doanvanhieu

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