Need trim function included in the transpose function, can someone help me on this.

tv9_rohith

Board Regular
Joined
Sep 1, 2011
Messages
96
Hi

Currently Im using formula:

Dim LR As Long
LR = Range("A" & Rows.count).End(xlUp).Row
Range("G9").Value = Join(Application.Transpose(Range("A2:A" & LR)), ", ")

but I want include Trim function in it.

before transpose the data first it should trim it then it should transpose.

could someone help me on this.

Regards,
Rohith M
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try

Code:
Dim LR As Long, s As String, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LR
    s = s & Trim(Range("A" & i).Value) & ", "
Next i
Range("G9").Value = Left(s, Len(s) - 2)
 
Upvote 0
And samll addition to that - If there is no data in the colum A then, it should display msgbox "Please enter the data ". if there is a data then it will execute the below formular.

Dim LR As Long, s As String, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LR
s = s & Trim(Range("A" & i).Value) & ", "
Next i
Range("G9").Value = Left(s, Len(s) - 2)
 
Upvote 0
Try

Code:
Dim LR As Long, s As String, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
If WorksheetFunction.CountA(Range("A2:A" & LR)) = 0 Then
    MsgBox "Please enter the data", vbExclamation
    Exit Sub
End If
For i = 2 To LR
    s = s & Trim(Range("A" & i).Value) & ", "
Next i
Range("G9").Value = Left(s, Len(s) - 2)
 
Upvote 0
I don't get an error. What is the exact error message? What values do you have in column A?

My quick test

Excel Workbook
ABCDEFG
2a
3b
4d
5
6
7
8
9a, b, d
Sheet2
 
Upvote 0
I have assigned this formula to Commandbutton and without entering the data in Coulmn A I thried using this formula and the code is not getting executed.

Want want is if there is no data in coulmn A and if we try to click tha command button then it should show up the message like Please enter the data.

If I enter the data in colum A then press the command button then it should execute the formula - Trim, Transpose .

I think this is clear
 
Upvote 0
This works fine for me with the button on the same sheet as the data

Code:
Private Sub CommandButton1_Click()
Dim LR As Long, s As String, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
If WorksheetFunction.CountA(Range("A2:A" & LR)) = 0 Then
    MsgBox "Please enter the data", vbExclamation
    Exit Sub
End If
For i = 2 To LR
    s = s & Trim(Range("A" & i).Value) & ", "
Next i
Range("G9").Value = Left(s, Len(s) - 2)
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

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