|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Excel macro
Hi all,
Complete beginner, so if this is really obvious to someone could they please help out! I have a spreadsheet comprising say 100 blocks of repeating data each of 300 variables. This data is all contained in one huge column (this is how the data is written as text file by other software). Using: Sub test2() ' ' For x = 1 To 100 ' Range("A1:A300").Select Selection.Cut Range("B1").Select ActiveSheet.Paste Range("A1:A300").Select Application.CutCopyMode = False Selection.Delete Shift:=xlUp Next x End Sub I want to cut each block out of the primary column and paste it in another column alongside (Line 4 above). But I want to cut the next block and paste that to column C, then D, E, F, etc. How can I do this? When I tried before (wrongly!!) it all went nuts and if I leave it in the form above it simply overwrites all the data into column B. Cheers, Jon. |
|
#2
|
|||
|
|||
|
perhaps this should have gone in the "Beginners" forum
oops.................. Jon. |
|
#3
|
||||
|
||||
|
If I understand correctly, you want the information that is in A2 to go to B1, the information in A3 to C1, A4 to D1, etc.
If this is what you are trying 2 achieve, you must remember that there are less columns than there are rows. If not, sorry. (I have a knack 4 misunderstanding people - Try explain in a way I can understand ) Try the following untested code: Code:
dim i for i = 2 to 100 cells(1, i).value = cells(i, 1).value cells(i, 1).value = "" next i (I like the cells object much more than the range object, bcs you specify the rows (in integer, like you usually do), but the column is also specified as an integer, and not as a "B" or something like that. e.g. Cells(1, 5) will be the same as range("E1") ) |
|
#4
|
|||
|
|||
|
Perhaps should make this a little clearer (sorry for not explaining properly before!)
I am trying to extract data from cells A1:A300 and paste in B1:B300, then delete original A1:a300. Then I want to move data from A301:A600 to C1:C300; A601:A900 to D1 300, and so on until all 100 blocks (30,000 data points) have been moved into 100 separate columns.Hope this makes a bit more sense. Jon. |
|
#5
|
||||
|
||||
|
Sorry. Told you I'm clueless
Try this (You should modify it a bit 4 your use)Code:
Dim i
Dim bContinue
Dim iConst
iConst = 10
bContinue = True
i = 1
While bContinue
Range("A" & i & ":A" & (i + (iConst - 1))).Select
Selection.Cut
Cells(1, 1 + (i + iConst) \ iConst).Select
ActiveSheet.Paste
i = i + iConst
If Cells(i, 1).Value = "" Then
bContinue = False
End If
Wend
Hope I got it right this time! ![]() |
|
#6
|
|||
|
|||
|
Thats worked really well!!
Cheers! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Excel macro |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|