How to join columns of a table without continuity

%3CLINGO-SUB%20id%3D%22lingo-sub-2746541%22%20slang%3D%22en-US%22%3EHow%20to%20join%20columns%20of%20a%20table%20without%20continuity%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2746541%22%20slang%3D%22en-US%22%3E%3CDIV%3EGood%20afternoon.%20I%20want%20to%20format%20a%20set%20of%20columns%20in%20a%20table%2C%20which%20are%20not%20together.%3CBR%20%2F%3EI'm%20using%20this%20code%2C%20but%20I%20get%20an%20%22Application%20definition%20or%20object%20definition%20error%22%20error%20and%20I%20can't%20get%20over%20it.%20Thanks%3C%2FDIV%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3EWith%20Folha21.ListObjects(1).DataBodyRange%0A.Columns.Range(%22A%3AI%2CM%2CP%2CS%2CV%2CX%3AAF%2CAT%2CAV%2CAX%2CAZ%2CBA%2CBD%3ABE%2CBH%2CBL%3ABP%2CBS%2CBV%2CBY%22).NumberFormat%20%3D%20%22%40%22%0AEnd%20With%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2746541%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2746591%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20join%20columns%20of%20a%20table%20without%20continuity%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2746591%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1084899%22%20target%3D%22_blank%22%3E%40csoares%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20have%20to%20write%20the%20single-column%20ranges%20in%20C%3AC%20format%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3EWith%20Folha21.ListObjects(1).DataBodyRange%0A.Columns.Range(%22A%3AI%2CM%3AM%2CP%3AP%2CS%3AS%2CV%3AV%2CX%3AAF%2CAT%3AAT%2CAV%3AAV%2CAX%3AAX%2CAZ%3AAZ%2CBA%3ABA%2CBD%3ABE%2CBH%3ABH%2CBL%3ABP%2CBS%3ABS%2CBV%3ABV%2CBY%3ABY%22).NumberFormat%20%3D%20%22%40%22%0AEnd%20With%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EAlso%2C%20I%20don't%20think%20you%20need%20.Columns%20in%20there.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2747383%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20join%20columns%20of%20a%20table%20without%20continuity%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2747383%22%20slang%3D%22en-US%22%3EI%20still%20receive%20the%20same%20error%3C%2FLINGO-BODY%3E
Contributor
Good afternoon. I want to format a set of columns in a table, which are not together.
I'm using this code, but I get an "Application definition or object definition error" error and I can't get over it. Thanks

 

 

With Folha21.ListObjects(1).DataBodyRange
.Columns.Range("A:I,M,P,S,V,X:AF,AT,AV,AX,AZ,BA,BD:BE,BH,BL:BP,BS,BV,BY").NumberFormat = "@"
End With​

 

 

3 Replies

@csoares 

You have to write the single-column ranges in C:C format:

With Folha21.ListObjects(1).DataBodyRange
.Columns.Range("A:I,M:M,P:P,S:S,V:V,X:AF,AT:AT,AV:AV,AX:AX,AZ:AZ,BA:BA,BD:BE,BH:BH,BL:BP,BS:BS,BV:BV,BY:BY").NumberFormat = "@"
End With

Also, I don't think you need .Columns in there.

I still receive the same error

@csoares 

Could you attach a sample workbook without sensitive information?