Macro - Summing a Range and use the Range as the File Name

shhykk

New Member
Joined
Mar 27, 2015
Messages
12
Hi Experts,

I have pull together a set up codes, but the last bits is not working....

What the codes try to do:
1. Replace any blank cells in Column C with "OFFICE" (this part the macro is completed)
2. Find word "Group Totals" in the spreadsheet (this part the macro is completed)
3. In the same row as the "Group Totals", sum Column I to N. (Getting stuck)
4. The sum between Column I to N is then used as the file name (this part of the macro is completed)

Any help is appreciated :)

Kind regards,
Shhykk

Here's the code:-

Sub Macq_CMT()
'
Dim wks As Worksheet
Dim rng As Range
Dim LastRow As Long
Dim col As Long




Dim fileName As String
Dim TotalName As String
Dim myRange As Range


Dim iTotal As Long


Set wks = ActiveSheet
With wks

col = .Range("C8").Column


Set rng = .UsedRange 'try to reset the lastcell
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
Set rng = Nothing
On Error Resume Next
Set rng = .Range(.Cells(8, col), .Cells(LastRow, col)) _
.Cells.SpecialCells(xlCellTypeBlanks)
On Error GoTo 0


If rng Is Nothing Then
MsgBox "No blanks found"
Exit Sub
Else
rng.FormulaR1C1 = "OFFICE"
End If






End With


Columns("C:C").Select
iTotal = Selection.Find(What:="GROUP TOTALS (Disk) = ", After:=ActiveCell).Row



myRange = ActiveSheet.Range(Cells(ActiveCell.Row, 9), Cells(ActiveCell.Row, 14)).Select
TotalName = WorksheetFunction.Sum(myRange)





ChDir "D:\Documents and Settings\wongph\Desktop\My Download"
ActiveWorkbook.SaveAs fileName:= _
"D:\Documents and Settings\wongph\Desktop\My Download\CMT $" & WorksheetFunction.Text(TotalName, "#,###.00") & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False








End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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