Help improve my macros

rlekkala

New Member
Joined
Feb 3, 2009
Messages
49
I have two Macros
1) Adds a column with Updated field to correct date format from the below text format
<TABLE style="WIDTH: 259pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=345><COLGROUP><COL style="WIDTH: 259pt; mso-width-source: userset; mso-width-alt: 12617" width=345><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; WIDTH: 259pt; HEIGHT: 12.75pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl63 height=17 width=345>Found_In_Release_Date</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; WIDTH: 259pt; HEIGHT: 12.75pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl63 height=17 width=345>February 22, 2011 1:59:21 PM GMT-05:00</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; WIDTH: 259pt; HEIGHT: 12.75pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl63 height=17 width=345>June 25, 2011 3:22:05 PM GMT-05:00</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; WIDTH: 259pt; HEIGHT: 12.75pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" class=xl63 height=17 width=345>June 25, 2011 12:26:14 PM GMT-05:00</TD></TR></TBODY></TABLE>

Sub FixDate()
Dim a As Long, x As Long
x = Cells(Rows.Count, 15).End(xlUp).row
For a = 2 To x + 1
Cells(a, 16) = Left((Left(Cells(a, 15), 3) & " " & Right(Cells(a, 15), 26)), 9)
Cells(a, 16).NumberFormat = "yyyy - mm"
Next a
MsgBox "Corrected CQ date field is added"
End Sub

2) Adds the select columns and rows into sheet2 from sheet1.
Sub Transfer()
Dim row As Long
With ThisWorkbook.Worksheets("Sheet1")
row = Book1.Range("A" & Rows.Count).End(xlUp).row
If Not row > 1 Then Exit Sub
Book1.Range("A2:A" & row, "A2:P2").SpecialCells(xlCellTypeVisible).Copy _
ThisWorkbook.Worksheets("Sheet2").Cells(2, 1)
'End With
MsgBox "Defects table has been updated"
End Sub

What I want is for the datato be moved from Workbook1,sheet1 to Workbook2,Sheet1 Rather than two sheets between the same work book.

Aslo is is possible to combine 1) and 2), such that A single macro can add that extra column as in macro 1) and also move data into another sheet form another workbook like in macro 2)?

Help much appreciated thank you :)
 

Some videos you may like

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

rlekkala

New Member
Joined
Feb 3, 2009
Messages
49
Ok,
I finally got the twoi macros that work as I intended. I am pretty sure this can be improved to avoid errors (like if the book is alrady open etc). I am working on combining these two below macros into one. Any suggestions are most welcome.

1) How about the actual column name? Rather than c(a,16)
Sub FixDate()
Dim a As Long, x As Long
x = Cells(Rows.Count, 15).End(xlUp).row
For a = 2 To x + 1
Cells(a, 16) = Left((Left(Cells(a, 15), 3) & " " & Right(Cells(a, 15), 26)), 9)
Cells(a, 16).NumberFormat = "yyyy - mm"
Next a
MsgBox "Corrected CQ date field is added"
End Sub

2)Sub UpdateTable()
Dim row As Long
Workbooks("QueryResult").Sheets("IBM Rational ClearQuest Web").Activate
row = ActiveSheet.Range("A" & Rows.Count).End(xlUp).row
'Range = ActiveSheet.Range("A2:A" & row, "A2:P2")
ActiveSheet.Range("A2:A" & row, "A2:P2").Select
Application.CutCopyMode = False
Selection.Copy
Workbooks.Open Filename:="C:\Documents and Settings\AC29299\Desktop\SharePoint\SharePoint.xls"
Workbooks("SharePoint").Sheets("Defects").Activate
Cells(2, 1).Select
ActiveSheet.Paste
' myWorkbook("Sheet2").Cells(2, 1)
MsgBox "Defects table has been updated"
End Sub


The Sharepoint.xls has table that is set to auto expand so the new rows will automatically auto expand the table. But what if the new rows are less? It will leave the previous results. I would like to remove the ciurrent entries from rwo 2 and then paste the new values
 

Watch MrExcel Video

Forum statistics

Threads
1,123,271
Messages
5,600,650
Members
414,399
Latest member
Ninjee

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
Top