Cant combine cells to single string and write to cell

PanzerRanger

New Member
Joined
Jan 3, 2018
Messages
20
Using Excel 2013

If Im runing the code below in a for loop then comb works fine.

For Each c In Range("B2:B10") 'ersätt range
nr = Right(c, 3)
If nr = 980 Then
unr = c.Offset(0, -1)
se = c.Offset(0, 0)
comb = unr & " Sektion" & " " & se
Range("c4") = comb
End If
Next



but if comb looks like this
comb = unr & " Sektion " & se or comb = unr &" " & "Sektion" & " " & se

it generates a Type error 1004, but I need the spaces, any help because Im stuck out here

Many thanks
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
This works for me
Code:
For Each c In Range("B2:B10") 'ersätt range
nr = Right(c, 3)
If nr = 980 Then
unr = c.Offset(0, -1)
se = c.Offset(0, 0)
comb = unr & " Sektion " & se
Range("c4") = comb
End If
Next
What are the values of unr & se when it fails?
 
Upvote 0
Sheet looks like this

[TABLE="width: 131"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]Col A [/TD]
[TD] Col B[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]=H9K119[/TD]
[TD="align: right"]1000[/TD]
[/TR]
[TR]
[TD]=B4T119[/TD]
[TD="align: right"]1980[/TD]
[/TR]
[TR]
[TD]=B4B120[/TD]
[TD="align: right"]1981[/TD]
[/TR]
[TR]
[TD]=B4B121[/TD]
[TD="align: right"]1982[/TD]
[/TR]
[TR]
[TD]=B4B122[/TD]
[TD="align: right"]1983[/TD]
[/TR]
[TR]
[TD]=B4B123[/TD]
[TD="align: right"]1990[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
If you actually have an = sign in the col A values try
Code:
comb = "'" & unr & " Sektion " & se
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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