2

I have to write a position in the cell in the form of "1." with a macro. Whatever way I have tried to concatenate a number and a dot, it always only writes a number. If I add a strin before the number, the output is written properly. If I add another character after the dot, it also writes the outcome properly. Examples:

Sub concat()
Dim currentSht As Worksheet
Dim position, dot As String
Dim checkRow1 As Integer
Set currentSht = Sheets("Predtekmovanje")
position = "2"
dot = ".h"
currentSht.Range("AY8").Value = CStr(position) & dot
End Sub

If somebody finds a clever way on how to make the output in the form of 2. in the cell, I would really appresciate it.

1
  • Are you sure that the actual data of the cell is wrong? It sounds like the issue is that Excel formats the value as a number. Commented Aug 23, 2016 at 11:55

2 Answers 2

1

First change the number format to Text and then add the value.

currentSht.Range("AY8").NumberFormat="@"
currentSht.Range("AY8").Value="1."
Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried a custom number format? Like this:

With Sheet1.Range("A2")
    .NumberFormat = "#."
    .Value = position
End With

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.