Macro help - Showing my newbieness

Norm Shea

New Member
Joined
Jul 31, 2007
Messages
19
Office Version
  1. 365
Platform
  1. Windows
I'm trying to write a macro and I'm having a little trouble. This is the data I have. It starts out with a reading number in B2 followed by a depth in B3, then a reading number in B4, depth in B5, etc.

Easting Northing
976 2,277,532.23 282,552.47
-1.4 2,277,529.03 282,549.27
975 2,277,530.50 282,560.28
1.2 2,277,527.30 282,557.08
974 2,277,528.33 282,570.05
2.4 2,277,525.13 282,566.84

I'd like to have it look like this where the reading from B2 is pasted in A3 and then row B is deleted entirely. I did already add the Reading and Depth columns so I just need to start on the data in B2

Reading Depth Easting Northing
976 -1.4 2,277,529.03 282,549.27
975 1.2 2,277,527.30 282,557.08

I have 1157 rows of data.

This is a macro I started but couldn't get it to work completely.

Sub ReadingsMove()
'
' ReadingsMove Macro
'

'
ActiveCell.Offset(1, 1).Range("A1").Select
Selection.Cut
ActiveCell.Offset(1, -1).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Offset(-1, 0).Rows("1:1").EntireRow.Select
Selection.Delete Shift:=xlUp
End Sub

Can someone let me know what I'm missing?
Thanks,
Norm
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Here is the post with the spacing I was anticipating. Didn't know tabs didn't work in here, didn't do "preview post" and timed out on my editing window.

I'm trying to write a macro and I'm having a little trouble. This is the data I have. It starts out with a reading number in B2 followed by a depth in B3, then a reading number in B4, depth in B5, etc.

___________________Easting________Northing
______________976_2,277,532.23___282,552.47
______________-1.4_2,277,529.03___282,549.27
______________975_2,277,530.50___282,560.28
______________1.2_2,277,527.30___282,557.08
______________974_2,277,528.33___282,570.05
______________2.4_2,277,525.13___282,566.84

I'd like to have it look like this where the reading from B2 is pasted in A3 and then row B is deleted entirely. I did already add the Reading and Depth columns so I just need to start on the data in B2

Reading____Depth___Easting_________Northing
976________-1.4__2,277,529.03_____282,549.27
975________1.2___2,277,527.30_____282,557.08

I have 1157 rows of data.

This is a macro I started but couldn't get it to work completely.

Sub ReadingsMove()
'
' ReadingsMove Macro
'

'
ActiveCell.Offset(1, 1).Range("A1").Select
Selection.Cut
ActiveCell.Offset(1, -1).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Offset(-1, 0).Rows("1:1").EntireRow.Select
Selection.Delete Shift:=xlUp
End Sub

Norm
 
Upvote 0
Any ideas?

I'm trying to write a macro and I'm having a little trouble. This is the data I have. It starts out with a reading number in B2 followed by a depth in B3, then a reading number in B4, depth in B5, etc.

___________________Easting________Northing
______________976_2,277,532.23___282,552.47
______________-1.4_2,277,529.03___282,549.27
______________975_2,277,530.50___282,560.28
______________1.2_2,277,527.30___282,557.08
______________974_2,277,528.33___282,570.05
______________2.4_2,277,525.13___282,566.84

I'd like to have it look like this where the reading from B2 is pasted in A3 and then row B is deleted entirely. I did already add the Reading and Depth columns so I just need to start on the data in B2

Reading____Depth___Easting_________Northing
976________-1.4__2,277,529.03_____282,549.27
975________1.2___2,277,527.30_____282,557.08

I have 1157 rows of data.

This is a macro I started but couldn't get it to work completely.

Sub ReadingsMove()
'
' ReadingsMove Macro
'

'
ActiveCell.Offset(1, 1).Range("A1").Select
Selection.Cut
ActiveCell.Offset(1, -1).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Offset(-1, 0).Rows("1:1").EntireRow.Select
Selection.Delete Shift:=xlUp
End Sub

Norm
 
Upvote 0
Norm Shea,

1. What version of Excel and Windows are you using?

2. Are you using a PC or a Mac?


We can not tell by your text displays, what cells, rows, columns your data is in, and, we can not tell what cells, rows, columns your results are in.


So that we can get it right the first time:

Can you post a screenshot of the actual raw data worksheet?

And, can you post a screenshot of the worksheet results (manually formatted by you) that you are looking for?

To post your data, you can download and install one of the following two programs:
Excel Jeanie
MrExcel.com | Excel Resources | Excel Seminars | Excel Products

Or, when using Internet Explorer, just put borders around your data in Excel and copy those cells into your post.
See reply #2 the BLUE text in the following link:
http://www.mrexcel.com/forum/about-board/444901-how-create-table-like-aladin.html#post2198045


If you are not able to give us screenshots:
You can upload your workbook to Box Net,
sensitive data changed
mark the workbook for sharing
and provide us with a link to your workbook.
 
Upvote 0
The following macro is based on your data laid out as follows...


ABCDE
1
2 9762,277,532.23282,552.47
3 -1.42,277,529.03282,549.27
4 9752,277,530.50282,560.28
5 1.22,277,527.30282,557.08
6 9742,277,528.33282,570.05
7 2.42,277,525.13282,566.84
8

<colgroup><col style="width: 30px; font-weight: bold;"><col style="width: 64px;"><col style="width: 112px;"><col style="width: 82px;"><col style="width: 71px;"><col style="width: 64px;"></colgroup><tbody>
</tbody>

After the code, it will look like this...


ABCDE
1
2976-1.42,277,529.03282,549.27
39751.22,277,527.30282,557.08
49742.42,277,525.13282,566.84
5

<colgroup><col style="width: 30px; font-weight: bold;"><col style="width: 64px;"><col style="width: 112px;"><col style="width: 82px;"><col style="width: 71px;"><col style="width: 64px;"></colgroup><tbody>
</tbody>

Code:
Sub MoveReadingAndDisplayDepthRowsOnly()
  Dim LastRow As Long
  LastRow = Cells(Rows.Count, "B").End(xlUp).Row
  Range("A3:A" & LastRow) = Evaluate("IF(MOD(ROW(A3:A" & LastRow & "),2),B2:B" & LastRow - 1 & ","""")")
  Range("A2:A" & LastRow).SpecialCells(xlBlanks).EntireRow.Delete
End Sub
 
Upvote 0
Solution
Norm Shea,

Sample raw data:


Excel 2007
ABCD
1ReadingDepthEastingNorthing
29762,277,532.23282,552.47
3-1.42,277,529.03282,549.27
49752,277,530.50282,560.28
51.22,277,527.30282,557.08
69742,277,528.33282,570.05
72.42,277,525.13282,566.84
8
Sheet1


After the macro:


Excel 2007
ABCD
1ReadingDepthEastingNorthing
2976-1.42,277,529.03282,549.27
39751.22,277,527.30282,557.08
49742.42,277,525.13282,566.84
5
6
7
8
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Code:
Sub ReorgData()
' hiker95, 03/29/2014, ME767558
Dim r As Long, lr As Long
lr = Cells(Rows.Count, 2).End(xlUp).Row
For r = 2 To lr Step 2
  Cells(r + 1, 1).Value = Cells(r, 2).Value
  Cells(r, 2) = ""
Next r
On Error Resume Next
Range("B2", Range("B" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the ReorgData macro.
 
Upvote 0
hiker95,
It's Excel 2007 on a Windows 7 PC. Next time I'll include a screen shot.
Norm
 
Upvote 0
Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Code:
Sub ReorgData()
' hiker95, 03/29/2014, ME767558
Dim r As Long, lr As Long
lr = Cells(Rows.Count, 2).End(xlUp).Row
For r = 2 To lr Step 2
  Cells(r + 1, 1).Value = Cells(r, 2).Value
  Cells(r, 2) = ""
Next r
On Error Resume Next
Range("B2", Range("B" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the ReorgData macro.

hiker95,
Thanks, that worked, too. I appreciate the assistance. It is certainly a more complex routine that I anticipated and would never come up with that. Thanks again.
Norm
 
Upvote 0
Norm Shea,

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,447
Members
448,966
Latest member
DannyC96

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top