Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-20-2011, 08:24 AM
tareq tareq is offline How to use "if" to copy and paste data Windows 7 How to use "if" to copy and paste data Office 2007
Novice
How to use "if" to copy and paste data
 
Join Date: Sep 2010
Posts: 15
tareq is on a distinguished road
Default

Quote:
Originally Posted by BjornS View Post
Hi again,
as I see it there are two main issues.

a) To make your macro work for 28-31 days
b) to add the extra rows for the hours "inbetween".



Regarding (a), it is not always easy to adjust an already recorded macro (much easier if it was "programmed"). One way of solving this is the following:
1) Re-record your macro for a month with 31 days (for example July).
2) Save this as your "permanent macro", that you in the future use for every month.
3) Run this macro for a short month (February, April, June etc). Please publish the result of this macro run (= how your excel sheet "my macro" looks like for april) here, so I can have a look at it. Then I can see if I can create an additional macro, that simply deletes the extra rows.

Regarding (b) I am looking at it, but I am quite busy the next 2-3 days.

Kind regards
Bjorn
Hi, I will do the macro again and post it ASAP. Thank you )
Reply With Quote
  #2  
Old 01-21-2011, 02:18 PM
BjornS BjornS is offline How to use "if" to copy and paste data Windows Vista How to use "if" to copy and paste data Office 2003
Competent Performer
 
Join Date: Jan 2010
Location: Sweden
Posts: 116
BjornS is on a distinguished road
Default

Hi,
try this!

Activate the sheet "My Macros" and then run the macro below. This should turn this sheet into same appearance as the sheet "Final".

Kind regards
Bjorn


Sub FixRows()
Application.ScreenUpdating = False
Dim rownum As Long
Dim rowhour As Long
rownum = 4
rowhour = 0
Do Until Cells(rownum, 4).Value = "" And rowhour = 0
If Cells(rownum, 4).Value <> rowhour And Cells(rownum, 4).Value Mod 100 = 0 Then

Cells(rownum, 1).EntireRow.Insert
Cells(rownum - 1, 1).Range("A1:L1").Copy _
Destination:=Cells(rownum, 1)
Cells(rownum, 4).Value = rowhour
If rowhour Mod 300 = 0 Then
With Cells(rownum, 5)
.NumberFormat = "0"
.FormulaR1C1 = "9999"
.Interior.ColorIndex = 6
.Interior.Pattern = xlSolid
.Borders.LineStyle = xlcontinous
.Borders.Weight = xlThin
.Borders.ColorIndex = xlAutomatic
End With
Cells(rownum, 5).Copy Destination:=Cells(rownum, 1).Range("E1:L1")
End If

End If

rownum = rownum + 1
rowhour = rowhour + 100
If rowhour = 2400 Then rowhour = 0
Loop
Application.ScreenUpdating = False
End Sub
Reply With Quote
  #3  
Old 01-21-2011, 04:59 PM
tareq tareq is offline How to use &quot;if&quot; to copy and paste data Windows 7 How to use &quot;if&quot; to copy and paste data Office 2007
Novice
How to use &quot;if&quot; to copy and paste data
 
Join Date: Sep 2010
Posts: 15
tareq is on a distinguished road
Default

Quote:
Originally Posted by BjornS View Post
Hi,
try this!

Activate the sheet "My Macros" and then run the macro below. This should turn this sheet into same appearance as the sheet "Final".

Kind regards
Bjorn


Sub FixRows()
Application.ScreenUpdating = False
Dim rownum As Long
Dim rowhour As Long
rownum = 4
rowhour = 0
Do Until Cells(rownum, 4).Value = "" And rowhour = 0
If Cells(rownum, 4).Value <> rowhour And Cells(rownum, 4).Value Mod 100 = 0 Then

Cells(rownum, 1).EntireRow.Insert
Cells(rownum - 1, 1).Range("A1:L1").Copy _
Destination:=Cells(rownum, 1)
Cells(rownum, 4).Value = rowhour
If rowhour Mod 300 = 0 Then
With Cells(rownum, 5)
.NumberFormat = "0"
.FormulaR1C1 = "9999"
.Interior.ColorIndex = 6
.Interior.Pattern = xlSolid
.Borders.LineStyle = xlcontinous
.Borders.Weight = xlThin
.Borders.ColorIndex = xlAutomatic
End With
Cells(rownum, 5).Copy Destination:=Cells(rownum, 1).Range("E1:L1")
End If

End If

rownum = rownum + 1
rowhour = rowhour + 100
If rowhour = 2400 Then rowhour = 0
Loop
Application.ScreenUpdating = False
End Sub
WOW!! It worked!!! Thank you very much, I will try on a full data, I will try it for a year and I will let you know about the results, and tomorrow I will attach the re-recorded macro. Again, thank you very much BjornS ) you saved me )
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Wierd symbols inplace of "space", "indentation" etc aka.bhagvanji Word 5 02-16-2012 11:50 AM
How to use &quot;if&quot; to copy and paste data Replacing a single "l" with a double "ll" MShroff Word 8 01-19-2011 08:43 AM
"Microsoft Excel Application" missing in the "Component Services" on win08 sword.fish Excel 0 02-26-2010 02:09 PM
How do I change the "and" to "or" with multiple Rules (and Alerts)? bschimmel Outlook 0 11-16-2009 05:26 AM
Saving only "DATA" on excel? No white bottom? jrasche2003@yahoo.com Excel 0 08-07-2006 09:27 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:14 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft