I am trying to transform a list of operations to a For loop in Excel VBA.
Sheets("Clients").Select
Range("A7").Select
Selection.Copy
Sheets("DB TEMP").Select
Range("A2:A13").Select
ActiveSheet.Paste
Sheets("Clients").Select
Range("B7,D7,F7,H7,J7,L7,N7,P7,R7,T7,V7,X7").Select
Selection.Copy
Sheets("DB TEMP").Select
Range("E2").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
And imagine that you have to do that for x times I started thinking create a For loop maybe it is as easy as in Python.
Here is my code for now (that is not working)
Dim Cellule As Range
Dim Feuille As Worksheet
Sheets("Clients").Select
For Each Cellule In Range("A1:A260") 'For all cells in the column A
If Cellule <> "" Then '#if the cell is not null
Cellule.Select '#select the cell (if possible to select the adjacent one too in B
Selection.Copy '#copy it
Sheets("DB TEMP").Select '#go to other sheets
With Sheets("DB TEMP") '#go find the last row available in column A
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
End With
ActiveSheet.Paste '#paste the data
Sheets("Clients").Select '#Back in my main sheets
Range(Cells(Cellule.ActiveCell.Row, B), Cells(Cellule.ActiveCell.Row, D), Cells(Cellule.ActiveCell.Row, F), Cells(Cellule.ActiveCell.Row, H), Cells(Cellule.ActiveCell.Row, J), Cells(Cellule.ActiveCell.Row, L), Cells(Cellule.ActiveCell.Row, N), Cells(Cellule.ActiveCell.Row, P), Cells(Cellule.ActiveCell.Row, R), Cells(Cellule.ActiveCell.Row, T), Cells(Cellule.ActiveCell.Row, V), Cells(Cellule.ActiveCell.Row, X)).Select
Selection.Copy
Sheets("DB TEMP").Select
With Sheets("DB TEMP")
LastRow = .Range("E" & .Rows.Count).End(xlUp).Row
End With
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
End If
Range(Cells(Cellule.ActiveCell.Row, B) .... this line is supposed to select all the cells with the same row number that is active (Cellule previously)
With Sheets("DB TEMP") ....same stuff as the other one I want to paste it to the other sheets and transpose it from the last row available.
I think I have errors in the Range selection and how to tell excel that my row is the same number.
When I try to run the only first part of the For loop I only get my last none null data to be paste to the other sheets (what about the others even if i see excel check every one of them during the process)
Thank you in advance for any clues on that!
.SelectsandSelections.by combining them i.e.Cellule.Copy