Try this:
Option Explicit
Sub Moorings()
Dim w1 As Worksheet
Dim w2 As Worksheet
Set w1 = Sheets("Sheet1")
Set w2 = Sheets("Sheet2")
Dim lr As Long
lr = w1.Range("A" & Rows.Count).End(xlUp).Row
Dim a As Long, b As Long, c As Long, d As Long, e As Long
Dim f As Long, g As Long, h As Long, k As Long, j As Long
Dim i As Long
Application.ScreenUpdating = False
For i = 1 To lr
a = w2.Range("A" & Rows.Count).End(xlUp).Row
b = w2.Range("B" & Rows.Count).End(xlUp).Row
c = w2.Range("C" & Rows.Count).End(xlUp).Row
d = w2.Range("D" & Rows.Count).End(xlUp).Row
e = w2.Range("E" & Rows.Count).End(xlUp).Row
f = w2.Range("F" & Rows.Count).End(xlUp).Row
g = w2.Range("G" & Rows.Count).End(xlUp).Row
h = w2.Range("H" & Rows.Count).End(xlUp).Row
k = w2.Range("I" & Rows.Count).End(xlUp).Row
j = w2.Range("J" & Rows.Count).End(xlUp).Row
If Range("A" & i) = "Name:" Then
Range("A" & i).Offset(0, 1).Copy w2.Range("A" & a + 1)
ElseIf Range("A" & i) = "Lat/Long:" Then
Range("A" & i).Offset(0, 1).Copy w2.Range("B" & b + 1)
ElseIf Range("A" & i) = "Reference:" Then
Range("A" & i).Offset(0, 1).Copy w2.Range("C" & c + 1)
ElseIf Range("A" & i) = "Location:" Then
Range("A" & i).Offset(0, 1).Copy w2.Range("D" & d + 1)
ElseIf Range("A" & i) = "Mooring:" Then
Range("A" & i).Offset(0, 1).Copy w2.Range("E" & e + 1)
ElseIf Range("A" & i) = "Facilities:" Then
Range("A" & i).Offset(0, 1).Copy w2.Range("F" & f + 1)
ElseIf Range("A" & i) = "Costs:" Then
Range("A" & i).Offset(0, 1).Copy w2.Range("G" & g + 1)
ElseIf Range("A" & i) = "Amenities:" Then
Range("A" & i).Offset(0, 1).Copy w2.Range("H" & h + 1)
ElseIf Range("A" & i) = "Contributors:" Then
Range("A" & i).Offset(0, 1).Copy w2.Range("I" & k + 1)
ElseIf Range("A" & i) = "Last Update:" Then
Range("A" & i).Offset(0, 1).Copy w2.Range("J" & j + 1)
End If
Next i
Application.CutCopyMode = False
Application.ScreenUpdating = False
MsgBox ("completed")
End Sub
A couple of changes I would suggest your your current data. You have used in some cases two cells one above the other for information. ie.B6 and B7. Make sure all the data is in one cell or it will not transfer properly. Put the data from B7 into the end of B6. There are several places that you need to do this.
How to install your new code
- Copy the Excel VBA code
- Select the workbook in which you want to store the Excel VBA code
- Press Alt+F11 to open the Visual Basic Editor
- Choose Insert > Module
- Edit > Paste the macro into the module that appeared
- Close the VBEditor
- Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)
To run the Excel VBA code:- Press Alt-F8 to open the macro list
- Select a macro in the list
- Click the Run button
Bookmarks