• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Need Macro for create address book

jack999

Member
I have excel workbook contains Name and address as on the format of sample workbook sheet2. I want to copy it in the format of sheet1 of sample workbook. Sheet1 data contains in alphabetical order.Data of Sheet2 starts from B2. I need a macro for copy this data from sheet2 to Sheet1 as the format uploaded.

Thanks
 

Attachments

  • address.xlsx
    9.5 KB · Views: 11
Hi Jack,

check if its works for you..

Code:
Sub SpliMultiple()
Dim frw As Long, lrw As Long, fcol As Long, lcol As Long, deb As Range
Set deb = Sheets(2).Range("B1").CurrentRegion
frw = deb.Cells(1).Row + 1
lrw = 1
fcol = deb.Cells(1, 1).Column
lcol = deb.Columns.Count + fcol - 1
 
Sheets(1).Select
For i = 1 To deb.Rows.Count
    Range(Cells(lrw, frw), Cells(lrw + deb.Columns.Count - 1, frw)) = WorksheetFunction.Transpose(deb.Rows(i))
    lrw = Cells(lrw, fcol).Row + deb.Columns.Count + 1
Next i
End Sub
 
With your data being systematic, you use a formula as well.
In Sheet2, Cell B2 insert following formula
Code:
=INDEX(Sheet1!$B$1:$B$100,(ROWS($A$1:A1)-1)*6+COLUMNS($A$1:A1))
and then copy down and across until you get errors. Make sure you adjust $B$100 part to actual last row of your data.
 
Hi Jack,

check if its works for you..

Code:
Sub SpliMultiple()
Dim frw As Long, lrw As Long, fcol As Long, lcol As Long, deb As Range
Set deb = Sheets(2).Range("B1").CurrentRegion
frw = deb.Cells(1).Row + 1
lrw = 1
fcol = deb.Cells(1, 1).Column
lcol = deb.Columns.Count + fcol - 1
 
Sheets(1).Select
For i = 1 To deb.Rows.Count
    Range(Cells(lrw, frw), Cells(lrw + deb.Columns.Count - 1, frw)) = WorksheetFunction.Transpose(deb.Rows(i))
    lrw = Cells(lrw, fcol).Row + deb.Columns.Count + 1
Next i
End Sub
Thanks A Lot
 
With your data being systematic, you use a formula as well.
In Sheet2, Cell B2 insert following formula
Code:
=INDEX(Sheet1!$B$1:$B$100,(ROWS($A$1:A1)-1)*6+COLUMNS($A$1:A1))
and then copy down and across until you get errors. Make sure you adjust $B$100 part to actual last row of your data.
Sir, I want to copy from sheet2 to Sheet1; Copy paste special transpose wise.
 
Yes. That is pretty much doable using formula I have posted. I am attaching modified file for your reference.
 

Attachments

  • address-1.xlsx
    13 KB · Views: 8
Hi Jack,

check if its works for you..

Code:
Sub SpliMultiple()
Dim frw As Long, lrw As Long, fcol As Long, lcol As Long, deb As Range
Set deb = Sheets(2).Range("B1").CurrentRegion
frw = deb.Cells(1).Row + 1
lrw = 1
fcol = deb.Cells(1, 1).Column
lcol = deb.Columns.Count + fcol - 1
 
Sheets(1).Select
For i = 1 To deb.Rows.Count
    Range(Cells(lrw, frw), Cells(lrw + deb.Columns.Count - 1, frw)) = WorksheetFunction.Transpose(deb.Rows(i))
    lrw = Cells(lrw, fcol).Row + deb.Columns.Count + 1
Next i
End Sub
Some error showing as follows
When I run the macro its copy Sheet2 Heading also to the sheet1. Sheet2 Column A contains formula.
Actually range is Sheet2 B2:F200

When I remove sheet2 Column A and Heading its copying properly.
Can you modify this code as suitable for me
Thanks and Regards
 
Hi Jack,

check if its works for you..

Code:
Sub SpliMultiple()
Dim frw As Long, lrw As Long, fcol As Long, lcol As Long, deb As Range
Set deb = Sheets(2).Range("B1").CurrentRegion
frw = deb.Cells(1).Row + 1
lrw = 1
fcol = deb.Cells(1, 1).Column
lcol = deb.Columns.Count + fcol - 1
 
Sheets(1).Select
For i = 1 To deb.Rows.Count
    Range(Cells(lrw, frw), Cells(lrw + deb.Columns.Count - 1, frw)) = WorksheetFunction.Transpose(deb.Rows(i))
    lrw = Cells(lrw, fcol).Row + deb.Columns.Count + 1
Next i
End Sub
Sir, Can you modify the cod as I replied before.
 
oops.. I missed the post.. :(

try the same..
just change this line..


For i = 2 To deb.Rows.Count

complete code pasted again..

Code:
Sub SpliMultiple()
Dim frw As Long, lrw As Long, fcol As Long, lcol As Long, deb As Range
Set deb = Sheets(2).Range("B1").CurrentRegion
frw = deb.Cells(1).Row + 1
lrw = 1
fcol = deb.Cells(1, 1).Column
lcol = deb.Columns.Count + fcol - 1
 
Sheets(1).Select
For i = 2 To deb.Rows.Count
    Range(Cells(lrw, frw), Cells(lrw + deb.Columns.Count - 1, frw)) = WorksheetFunction.Transpose(deb.Rows(i))
    lrw = Cells(lrw, fcol).Row + deb.Columns.Count + 1
Next i
End Sub

lemme know if you need the heading also in sheet1 > column A..
 
Back
Top