Hi I am fairly new to VBA. I have a sheet which has a data from column A10 to M67. Now I want this data to be copied to column Q9 (so Q9 should show data from cell A10) , after this I would like to leave 2 rows gap below and go to cell Q12 and get the data from A11 and repeat it till the columns A is blank.
There has to be some simple way with either the formulas or macros but was not able to solve it.
This means fill data on Q9 from A10, then go to Q12 and get data from A11.
Q9=A10
Q12=A11
Q15=A12
Q18=A13
I have attached the spreadsheet and shown the example.
Last edited by talhawahab; 03-31-2011 at 08:19 PM.
hi, talhawahab, please check attachment, run code "test"
Thanks Watersev...the code works brilliantly....I didn't understand what the code meant but does the job.
I only had one issue with the code after the code is run. the two lines which are copied are identical in Q9 and Q10 and that is fine. The problem is the only difference the second line should have is: if 1st line (row9) have figures in Credit column (column W), there should be figures in Debit Column (column V) in row 10 and viceversa.
hi, sorry, I did miss that part, corrected, please check attachment.
I assume in Debits and Credits columns we will always have one value and zero as a rule.
Thanks Watersev now the code is perfect!....you have saved lot of my time and lots of stress!!! very thankful to you. fully solved! Dr and cr are fine now![]()
hi again...I have one small problem again...can you replace cell U10,U13,U16 (all second line) with one fix account number which would be in cell (P1).
Thnks watersev again....ur a gem...
Hi again,
I would like to get a quick help from you please. I have two issues but I think are small and I am stuck with it.
First, if any (number/text) in cell U9, U12, U15, U18, U21 and so on is starting with "1" i.e (left("U9",1)="1") (for eg: 11210 or 1-6110) . if yes, Then delete that row (Q9:Y9) and one below (Q10:Y10) and repeat it but going --> going to U12.
'(only do this in U9, U12, U15, U18, U21 and so on.
'I had created the macro (macro name: clearing_line_which_has_1()
see below or see in the attached spreadsheet.
The second issue is where the data is 'copied from left side to right, (cell Q9:Y9) at the bottom (cell u34)....12110 remains (in cell U34,U37,U40). I would like to get rid of those numbers.Sub clearing_line_which_has_1() ActiveSheet.Select Range("U9").Select For x = 9 To 5000 If Left(Cells(x, 21), 1) = "1" Then Range(Cells(x, 17), Cells(x + 1, 25)).ClearContents Next x End Sub
I would really appreciate if you can help me with this.
hi, talhawahab
1. As far as I understand it's a separate task though it can be incorporated in "copy_data" (please advise if so). Sample of possible separate code:
2. I've amended the code "copy data" not to create those "empty" strings with account number from P1Sub test() Dim a, i As Long, k As Long With Range([q9], Cells(Rows.Count, "q").End(xlUp).Offset(, 8)): a = .Value For i = 1 To UBound(a) Step 3 If Left(a(i, 5), 1) = 1 Then Do k = k + 1: a(i + 1, k) = "" Loop Until k = 9: k = 0 End If Next: Application.ScreenUpdating = False: .Value = a: Application.ScreenUpdating = True End With: End Sub
If any outstanding issues or questions, please shout, best regardsSub copy_data() Dim a, b, n As Long, i As Long, m As Long, zctrl As Integer, SecondLineAcc As String Application.ScreenUpdating = False: SecondLineAcc = [p1] a = Range([a10], Cells(Rows.Count, "a").End(xlUp).Offset(, 10)): ReDim b(1 To UBound(a) * 3, 1 To 9): n = 1 For i = 1 To UBound(a) zctrl = IIf(a(i, 6) <> "", 1, 0) For m = 1 To UBound(b, 2) - 1 b(n, m) = IIf(IsEmpty(a(i, m)), "", a(i, m)): b(n + 1, m) = IIf(IsEmpty(a(i, m)), "", a(i, m)) Next b(n, 9) = IIf(IsEmpty(a(i, 9)), a(i, 11) & "-" & a(i, 4), a(i, 9)): b(n + 1, 9) = IIf(IsEmpty(a(i, 9)), a(i, 11) & "-" & a(i, 4), a(i, 9)) If zctrl = 1 Then b(n + 1, 7) = a(i, 6): b(n + 1, 6) = "" Else b(n + 1, 6) = a(i, 7): b(n + 1, 7) = "" End If b(n + 1, 5) = SecondLineAcc: b(n + 1, 8) = "": n = n + 3 Next: [q9].Resize(UBound(b), 9) = b Application.ScreenUpdating = True: End Sub
Last edited by watersev; 04-26-2011 at 04:08 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks