.value = .value

bsquad

Board Regular
Joined
Mar 15, 2016
Messages
194
I am guessing there isn't a possibility of this based on the purpose of .value;

But I am looking if there is a possibility of also taking the format on a .value = .value
I am trying to avoid a copy and paste

I have an example below

Code:
    Dim c As Range
        For Each c In Range("A2:B" & ThisWorkbook.Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row)
            If c.Value = "" Then c.Value = c.Offset(-1, 0).Value
    Next c
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Assuming the cells of interest are actually blanks (not zero-length strings),

Code:
Sub bsq()
  On Error GoTo noBlanks

  With ThisWorkbook.Worksheets("Sheet1").Range("A:B")
    .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=r[-1]c"
    .Value = .Value
  End With

noBlanks:
End Sub

That will replace any formulas in the range with values.
 
Upvote 0
Assuming the cells of interest are actually blanks (not zero-length strings),

Code:
Sub bsq()
  On Error GoTo noBlanks

  With ThisWorkbook.Worksheets("Sheet1").Range("A:B")
    .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=r[-1]c"
    .Value = .Value
  End With

noBlanks:
End Sub

That will replace any formulas in the range with values.
I had given a full column a Defined Name for another question I asked and even though I deleted that column, apparently the UsedRange did not "update" as your code filled the two columns down to the very last row on the sheet. On another sheet where I did not do that, your code worked perfectly. Just something for those using your code to watch out for. Anyway, here is an alternate which does not involve putting formulas on the sheet only to convert them to values afterwards...
Code:
[table="width: 500"]
[tr]
	[td]Sub bsquad()
  Dim Col As Long, Ar As Range
  For Col = 1 To 2
    For Each Ar In Sheets("Sheet1").Range(Cells(2, Col), Cells(Cells.Find("*", , xlValues, , xlRows, xlPrevious, , , False).Row, Col)).SpecialCells(xlBlanks).Areas
      Ar = Ar(1).Offset(-1)
    Next
  Next
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,215,931
Messages
6,127,765
Members
449,405
Latest member
Pavesib

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