Trying to Remove Single Quotes from Macro Outputs using VBA.

Tauben

New Member
Joined
Jul 1, 2015
Messages
2
I am currently trying to use the COUNTA function in Excel 13 to find the number of cells populated with data. When I execute my code it is supposed to insert the formula into the selected cell that would refer to other cells for the counting process. When it does this I am asked to open a file to find the sheet that it refers to even though it is in the same workbook.

Here is my code.

Private Sub CommandButton1_Click()

Dim rangeB As String

rangeB = "B10:B100"

Sheets("Form").Select ' Used because VBA would not select the cell without it being mentioned 2 times
Sheets("Form").Range("G13").Select
ActiveCell.Formula = _
"=COUNTA(Summary6-10!" & rangeB & ")"

End Sub

When I look at the cell G13 the formula is:
=COUNTA(Summary6-'10'!B10:B100)

The formula that I am trying to get is:
=COUNTA(Summary6-10!B10:B100)

I have simplified my code to see if I could eliminate the error but even with this code the single quotes still appear in the formula. Is my syntax wrong or is there something else that I am missing?

Any help would be greatly appreciated.
Thanks,
Garrett
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try this:

Code:
Dim rangeB As String

rangeB = "B10:B100"

Sheets("Form").Range("G13").Formula = "=COUNTA('Summary6-10'!" & rangeB & ")"
 
Upvote 0

Forum statistics

Threads
1,216,473
Messages
6,130,838
Members
449,597
Latest member
buikhanhsang

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