Jeanpierre
New Member
- Joined
- Jul 13, 2021
- Messages
- 11
- Office Version
- 365
- Platform
- Windows
Good day, I am newish to Visual Basic, apologies if this has been posted but i have searched through most of the forums and could not find this specific one. Basically what I need to do is a data sort from a file that information is not aligned properly.
It comes with information in Cell A, Cell B, Cell C, then Cell C2 (this cell needs to be text to column, comma sorted and then transposed), which I need to put in Cell A Cell B and Cell C.
The first part is easy, create a new data page, change data into columns (not sure if can avoid this step) as below:
Now i need to copy and paste the data from the demo sheet neatly into data output sheet but the cells in C2 need to be copied and transposed on data output sheet and then this code needs to be looped for every repeat of cell C1 & Cell C2 till no data in column C.
Images attached shows before and after, so I just need to loop it, and the code above might be primitive to the professionals, done with recording. Thank you.
It comes with information in Cell A, Cell B, Cell C, then Cell C2 (this cell needs to be text to column, comma sorted and then transposed), which I need to put in Cell A Cell B and Cell C.
The first part is easy, create a new data page, change data into columns (not sure if can avoid this step) as below:
VBA Code:
Columns("C:C").Select
Selection.TextToColumns Destination:=Range("C1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2), Array(5, 2)), TrailingMinusNumbers:=True
Sheets.Add After:=ActiveSheet
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "Data Output"
Sheets("Demo").Select
Range("C1").Select
Sheets("Data Output").Select
ActiveCell.FormulaR1C1 = "Cell A"
Range("B1").Select
ActiveCell.FormulaR1C1 = "Cell B"
Range("C1").Select
ActiveCell.FormulaR1C1 = "Cell C"
Range("A2").Select
Sheets("Demo").Select
Range("B1").Select
Selection.Copy
Sheets("Data Output").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Now i need to copy and paste the data from the demo sheet neatly into data output sheet but the cells in C2 need to be copied and transposed on data output sheet and then this code needs to be looped for every repeat of cell C1 & Cell C2 till no data in column C.
VBA Code:
Range("B2").Select
Sheets("Demo").Select
Range("C1").Select
Selection.Copy
Sheets("Data Output").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C2").Select
Sheets("Demo").Select
Range("C2:V2").Select
Selection.Copy
Sheets("Data Output").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Range("B2").Select
Application.CutCopyMode = False
Selection.Copy
Range("B3:B5").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A1").Select
Application.CutCopyMode = False
Images attached shows before and after, so I just need to loop it, and the code above might be primitive to the professionals, done with recording. Thank you.
VBA Code: