LostandConfused
New member
- Local time
- Today, 13:58
- Joined
- Feb 8, 2013
- Messages
- 6
A while back I created an Excel Macro that converts a plain spreadsheet we commonly get into a format that makes it easy to track items and removes all the columns I dont use. Well recently people want that macro from other organizations, and since I cannot figure out how to explain to them how to set it up I created an Access database that would import the document, and export it with all my nifty modifications. Only problem is, my VBA code from Excel is not working right in Access. I have discovered a way around it for most lines of code and I am going line by line fixing it, but one line will not work no matter what I try. It is a simple Replace function, the dates from the original document are stored as text and have "-" in them; I simply want to replace the "-" with a space " " but the same code that works great for this in Excel is not working in Access. I am using Access 2007, here is my code:
I am stuck on the line with the * in front. All the ' marks indicate lines of code from Excel that I haven't proven yet. All I need help with at the moment though is the * line. Any help would be greatly appreciated, I feel like I am going to pull all my hair out, lol.
Code:
Private Sub Export_EPR_Tracker_Click()
Dim FreshFile As String
FreshFile = FileOpenDialog
Dim dAt As String
dAt = " " & Format(Now(), "dd-mmm-yy")
Dim pA As String
pA = "C:\Users\nathan.mitson.AVIANO\Documents\MS Practice Stuff\EPR Trackers\EPR Tracker" & dAt & ".xlsx"
DoCmd.TransferSpreadsheet acExport, 10, "Alpha Roster Import", pA, True
Dim xlApp, xlBook As Object
Dim xlSheet As Object
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.workbooks.Add(pA)
Set xlSheet = xlApp.workbooks.Open(pA).sheets(1)
xlApp.Visible = True
Dim EPRDue1 As Variant
Dim EPRDue2 As Variant
Dim Val1 As Variant
Dim Val2 As Variant
Dim Val3 As Variant
Dim x As Variant
Dim LResult As String
With xlApp
.Application.sheets("Alpha_Roster_Import").Select
a = xlApp.Application.WorksheetFunction.CountA(xlApp.Range("B:B"))
x = 2
.Columns("C:C").Select
.Selection.Cut
.Columns("A:A").Select
.Selection.Insert Shift:=xlToRight
.Range("C:E, G:W, Y:AA, AC:AF, AH:AI, AK:AM, AO:BH").Delete
.Columns("G:G").Select
.Selection.Cut
.Columns("E:E").Select
.Selection.Insert Shift:=xlToRight
.Columns("H:H").Select
.Selection.Cut
.Columns("D:D").Select
.Selection.Insert Shift:=xlToRight
.Columns("G:G").Select
.Selection.Insert Shift:=xlToRight, _
CopyOrigin:=xlFormatFromLeftOrAbove
.Columns("G:G").Select
.Selection.Insert Shift:=xlToRight, _
CopyOrigin:=xlFormatFromLeftOrAbove
.Range("D:D, F:F, I:J").Select
**.Selection.Replace What:="-", Replacement:=" ", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
.Range("G1").Value = "DUE TO FLT"
.Range("H1").Value = "DUE TO SQ"
.Range("H2:H" & a).Formula = "=RC[1]-30"
.Range("G2:G" & a).Formula = "=RC[2]-45"
'Do
'Val1 = xlApp.Range("D" & x)
'Val2 = xlApp.Range("J" & x)
'Val3 = xlApp.Range("F" & x)
'EPRDue1 = Val1 - Val2
'EPRDue2 = Val1 - Val3
'If EPRDue1 > 120 And EPRDue1 < 364 And EPRDue2 > 120 Then
'.Range("I" & x).Value = xlApp.Range("D" & x) - 30
'End If
'x = x + 1
'Loop While x <= a
'.Cells.Select
'.Selection.WrapText = False
'.Cells.EntireColumn.Autofit
'.Cells.EntireRow.Autofit
'.Cells.Select
'.Selection.AutoFilter
'.Range("D2").Select
'.ActiveWindow.FreezePanes = True
'.Range("G:I").Select
'.Selection.FormatConditions.Add Type:=xlCellValue, _
'Operator:=xlLess, Formula1:="=TODAY()"
'.Selection.FormatCondition._
'(Selection.FormatConditions.Count).SetFirstPriority
' With Selection.FormatConditions(1).Interior
'.PatternColorIndex = xlAutomatic
'.Color = 255
'.TintAndShade = 0
'End With
'.Selection.FormatConditions.Add Type:=xlCellValue, _
'Operator:=xlBetween, Formula1:="=TODAY()", _
'Formula2:="=TODAY() + 5"
'.Selection.FormatConditions_
'(Selection.FormatConditions.Count).SetFirstPriority
'With Selection.FormatConditions(1).Interior
'.PatternColorIndex = xlAutomatic
'.Color = 65535
'.TintAndShade = 0
'End With
'.ActiveSheet.Range("$A$1:$J$434").AutoFilter Field:=3, _
'Criteria1:=Array("MXAB", "mxaba", "MXABC", "MXABD", "MXABF", _
'"MXABG", "MXABS", "mxabw"), Operator:=xlFilterValues
End With
Set xlApp = Nothing
Set xlBook = Nothing
End Sub
I am stuck on the line with the * in front. All the ' marks indicate lines of code from Excel that I haven't proven yet. All I need help with at the moment though is the * line. Any help would be greatly appreciated, I feel like I am going to pull all my hair out, lol.