VBA: Select multiple Columns till the last row to add a background color.
VBA code help Select multiple Columns till the last row to add a background color with easy-to-read code. Spent the last 3hrs trying everything I could find on the internet. Problem: I got co...
Yep, needs to be VBA. The point is to beautify my data.
I get 5 excel files, every day in the same fashion. excepts values are different. Row count ranging from 15-15k
I just want them to all look nicer, and have my eyes dart/go to where it's immediately needed. And I don't wanna keep doing conditional formatting 27 columns 5-7 times a day 25 days a month, with multiple clicks or spend lots of time. Just one quick macro and I'm done.
Btw, can you help me with the condition formatting of column D, labeled 'REASON'. I need for the selection to identify if the cell is empty or not. If it is not empty, then change the formatting (BGcolor and font)
I tried using a IF THEN, for each. with ISEMPTY and ISTEXT. it doesn't seem to do it.
As for all the other questions, I guess if it's too complex, I'll copy-paste the same code for each colored blocks. (makes the code twice as long, but at least it works)
Here is the code, I currently have, that applies a BG color to the selected range, but again doesn't apply a different formatting to Non-Empty cells in the same selected range.
Range("L2:M2").Resize(Lastrow).Select ' Where Lastrow is the last populated row in ColA
With Selection.Interior ' BG color all the selected cells
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent4
.TintAndShade = 0.599993896298105
.PatternTintAndShade = 0
End With
' The if statement to find which of the cells in the range is Non-Empty and add
' different formatting, i.e making it gold and italic
With Selection
If IsEmpty(Selection.Value) = True Then
.Font.Italic = True
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent4
.TintAndShade = 0.399975585192419
.PatternTintAndShade = 0
End If
End With
' Adding Borders to this selection
With Selection ' Adding Borders
.Borders.Weight = xlThin
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
End With
For Each TextCell In Selection
If TextCell <> "" Then
TextCell.Font.Italic = True
TextCell.Interior.Pattern = xlSolid
TextCell.Interior.PatternColorIndex = xlAutomatic
TextCell.Interior.ThemeColor = xlThemeColorAccent4
TextCell.Interior.TintAndShade = 0.399975585192419
TextCell.Interior.PatternTintAndShade = 0
End If
Next
Resources
"}},"componentScriptGroups({\"componentId\":\"custom.widget.MicrosoftFooter\"})":{"__typename":"ComponentScriptGroups","scriptGroups":{"__typename":"ComponentScriptGroupsDefinition","afterInteractive":{"__typename":"PageScriptGroupDefinition","group":"AFTER_INTERACTIVE","scriptIds":[]},"lazyOnLoad":{"__typename":"PageScriptGroupDefinition","group":"LAZY_ON_LOAD","scriptIds":[]}},"componentScripts":[]},"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"components/community/NavbarDropdownToggle\"]})":[{"__ref":"CachedAsset:text:en_US-components/community/NavbarDropdownToggle-1745505309806"}],"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"shared/client/components/common/QueryHandler\"]})":[{"__ref":"CachedAsset:text:en_US-shared/client/components/common/QueryHandler-1745505309806"}],"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"components/messages/EscalatedMessageBanner\"]})":[{"__ref":"CachedAsset:text:en_US-components/messages/EscalatedMessageBanner-1745505309806"}],"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"components/users/UserLink\"]})":[{"__ref":"CachedAsset:text:en_US-components/users/UserLink-1745505309806"}],"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"shared/client/components/users/UserRank\"]})":[{"__ref":"CachedAsset:text:en_US-shared/client/components/users/UserRank-1745505309806"}],"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"components/messages/MessageTime\"]})":[{"__ref":"CachedAsset:text:en_US-components/messages/MessageTime-1745505309806"}],"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"components/messages/MessageSolvedBadge\"]})":[{"__ref":"CachedAsset:text:en_US-components/messages/MessageSolvedBadge-1745505309806"}],"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"components/messages/MessageSubject\"]})":[{"__ref":"CachedAsset:text:en_US-components/messages/MessageSubject-1745505309806"}],"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"components/messages/MessageBody\"]})":[{"__ref":"CachedAsset:text:en_US-components/messages/MessageBody-1745505309806"}],"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"components/messages/MessageCustomFields\"]})":[{"__ref":"CachedAsset:text:en_US-components/messages/MessageCustomFields-1745505309806"}],"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"components/messages/MessageReplyButton\"]})":[{"__ref":"CachedAsset:text:en_US-components/messages/MessageReplyButton-1745505309806"}],"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"components/messages/MessageSolutionList\"]})":[{"__ref":"CachedAsset:text:en_US-components/messages/MessageSolutionList-1745505309806"}],"message({\"id\":\"message:3599540\"})":{"__ref":"ForumTopicMessage:message:3599540"},"messages({\"constraints\":{\"solution\":{\"eq\":true},\"topicId\":{\"eq\":\"message:3599540\"}},\"first\":10,\"sorts\":{\"postTime\":{\"direction\":\"ASC\"}}})":{"__typename":"MessageConnection","edges":[{"__typename":"MessageEdge","cursor":"MjUuMXwyLjF8aXwxMHwxMzI6MXxpbnQsMzYwMDE0NywzNjAwMTQ3","node":{"__ref":"AcceptedSolutionMessage:message:3600147"}}],"pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null},"totalCount":1},"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"shared/client/components/users/UserAvatar\"]})":[{"__ref":"CachedAsset:text:en_US-shared/client/components/users/UserAvatar-1745505309806"}],"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"shared/client/components/ranks/UserRankLabel\"]})":[{"__ref":"CachedAsset:text:en_US-shared/client/components/ranks/UserRankLabel-1745505309806"}],"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"components/messages/AcceptedSolutionButton\"]})":[{"__ref":"CachedAsset:text:en_US-components/messages/AcceptedSolutionButton-1745505309806"}],"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"components/messages/ThreadedReplyList\"]})":[{"__ref":"CachedAsset:text:en_US-components/messages/ThreadedReplyList-1745505309806"}],"message({\"id\":\"message:3600147\"})":{"__ref":"AcceptedSolutionMessage:message:3600147"},"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"components/tags/TagView/TagViewChip\"]})":[{"__ref":"CachedAsset:text:en_US-components/tags/TagView/TagViewChip-1745505309806"}],"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"components/attachments/AttachmentView/AttachmentViewChip\"]})":[{"__ref":"CachedAsset:text:en_US-components/attachments/AttachmentView/AttachmentViewChip-1745505309806"}],"cachedText({\"lastModified\":\"1745505309806\",\"locale\":\"en-US\",\"namespaces\":[\"shared/client/components/common/Pager/PagerLoadMore\"]})":[{"__ref":"CachedAsset:text:en_US-shared/client/components/common/Pager/PagerLoadMore-1745505309806"}],"message({\"id\":\"message:3600124\"})":{"__ref":"ForumReplyMessage:message:3600124"}},"CachedAsset:pages-1745487429407":{"__typename":"CachedAsset","id":"pages-1745487429407","value":[{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"BlogViewAllPostsPage","type":"BLOG","urlPath":"/category/:categoryId/blog/:boardId/all-posts/(/:after|/:before)?","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"CasePortalPage","type":"CASE_PORTAL","urlPath":"/caseportal","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"CreateGroupHubPage","type":"GROUP_HUB","urlPath":"/groups/create","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"CaseViewPage","type":"CASE_DETAILS","urlPath":"/case/:caseId/:caseNumber","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"InboxPage","type":"COMMUNITY","urlPath":"/inbox","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"HelpFAQPage","type":"COMMUNITY","urlPath":"/help","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"IdeaMessagePage","type":"IDEA_POST","urlPath":"/idea/:boardId/:messageSubject/:messageId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"IdeaViewAllIdeasPage","type":"IDEA","urlPath":"/category/:categoryId/ideas/:boardId/all-ideas/(/:after|/:before)?","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"LoginPage","type":"USER","urlPath":"/signin","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"BlogPostPage","type":"BLOG","urlPath":"/category/:categoryId/blogs/:boardId/create","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"UserBlogPermissions.Page","type":"COMMUNITY","urlPath":"/c/user-blog-permissions/page","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"ThemeEditorPage","type":"COMMUNITY","urlPath":"/designer/themes","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"TkbViewAllArticlesPage","type":"TKB","urlPath":"/category/:categoryId/kb/:boardId/all-articles/(/:after|/:before)?","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1730142000000,"localOverride":null,"page":{"id":"AllEvents","type":"CUSTOM","urlPath":"/Events","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"OccasionEditPage","type":"EVENT","urlPath":"/event/:boardId/:messageSubject/:messageId/edit","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"OAuthAuthorizationAllowPage","type":"USER","urlPath":"/auth/authorize/allow","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"PageEditorPage","type":"COMMUNITY","urlPath":"/designer/pages","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"PostPage","type":"COMMUNITY","urlPath":"/category/:categoryId/:boardId/create","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"ForumBoardPage","type":"FORUM","urlPath":"/category/:categoryId/discussions/:boardId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"TkbBoardPage","type":"TKB","urlPath":"/category/:categoryId/kb/:boardId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"EventPostPage","type":"EVENT","urlPath":"/category/:categoryId/events/:boardId/create","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"UserBadgesPage","type":"COMMUNITY","urlPath":"/users/:login/:userId/badges","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"GroupHubMembershipAction","type":"GROUP_HUB","urlPath":"/membership/join/:nodeId/:membershipType","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"MaintenancePage","type":"COMMUNITY","urlPath":"/maintenance","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"IdeaReplyPage","type":"IDEA_REPLY","urlPath":"/idea/:boardId/:messageSubject/:messageId/comments/:replyId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"UserSettingsPage","type":"USER","urlPath":"/mysettings/:userSettingsTab","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"GroupHubsPage","type":"GROUP_HUB","urlPath":"/groups","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"ForumPostPage","type":"FORUM","urlPath":"/category/:categoryId/discussions/:boardId/create","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"OccasionRsvpActionPage","type":"OCCASION","urlPath":"/event/:boardId/:messageSubject/:messageId/rsvp/:responseType","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"VerifyUserEmailPage","type":"USER","urlPath":"/verifyemail/:userId/:verifyEmailToken","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"AllOccasionsPage","type":"OCCASION","urlPath":"/category/:categoryId/events/:boardId/all-events/(/:after|/:before)?","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"EventBoardPage","type":"EVENT","urlPath":"/category/:categoryId/events/:boardId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"TkbReplyPage","type":"TKB_REPLY","urlPath":"/kb/:boardId/:messageSubject/:messageId/comments/:replyId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"IdeaBoardPage","type":"IDEA","urlPath":"/category/:categoryId/ideas/:boardId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"CommunityGuideLinesPage","type":"COMMUNITY","urlPath":"/communityguidelines","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"CaseCreatePage","type":"SALESFORCE_CASE_CREATION","urlPath":"/caseportal/create","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"TkbEditPage","type":"TKB","urlPath":"/kb/:boardId/:messageSubject/:messageId/edit","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"ForgotPasswordPage","type":"USER","urlPath":"/forgotpassword","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"IdeaEditPage","type":"IDEA","urlPath":"/idea/:boardId/:messageSubject/:messageId/edit","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"TagPage","type":"COMMUNITY","urlPath":"/tag/:tagName","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"BlogBoardPage","type":"BLOG","urlPath":"/category/:categoryId/blog/:boardId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"OccasionMessagePage","type":"OCCASION_TOPIC","urlPath":"/event/:boardId/:messageSubject/:messageId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"ManageContentPage","type":"COMMUNITY","urlPath":"/managecontent","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"ClosedMembershipNodeNonMembersPage","type":"GROUP_HUB","urlPath":"/closedgroup/:groupHubId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"CommunityPage","type":"COMMUNITY","urlPath":"/","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"ForumMessagePage","type":"FORUM_TOPIC","urlPath":"/discussions/:boardId/:messageSubject/:messageId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"IdeaPostPage","type":"IDEA","urlPath":"/category/:categoryId/ideas/:boardId/create","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1730142000000,"localOverride":null,"page":{"id":"CommunityHub.Page","type":"CUSTOM","urlPath":"/Directory","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"BlogMessagePage","type":"BLOG_ARTICLE","urlPath":"/blog/:boardId/:messageSubject/:messageId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"RegistrationPage","type":"USER","urlPath":"/register","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"EditGroupHubPage","type":"GROUP_HUB","urlPath":"/group/:groupHubId/edit","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"ForumEditPage","type":"FORUM","urlPath":"/discussions/:boardId/:messageSubject/:messageId/edit","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"ResetPasswordPage","type":"USER","urlPath":"/resetpassword/:userId/:resetPasswordToken","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1730142000000,"localOverride":null,"page":{"id":"AllBlogs.Page","type":"CUSTOM","urlPath":"/blogs","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"TkbMessagePage","type":"TKB_ARTICLE","urlPath":"/kb/:boardId/:messageSubject/:messageId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"BlogEditPage","type":"BLOG","urlPath":"/blog/:boardId/:messageSubject/:messageId/edit","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"ManageUsersPage","type":"USER","urlPath":"/users/manage/:tab?/:manageUsersTab?","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"ForumReplyPage","type":"FORUM_REPLY","urlPath":"/discussions/:boardId/:messageSubject/:messageId/replies/:replyId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"PrivacyPolicyPage","type":"COMMUNITY","urlPath":"/privacypolicy","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"NotificationPage","type":"COMMUNITY","urlPath":"/notifications","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"UserPage","type":"USER","urlPath":"/users/:login/:userId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"OccasionReplyPage","type":"OCCASION_REPLY","urlPath":"/event/:boardId/:messageSubject/:messageId/comments/:replyId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"ManageMembersPage","type":"GROUP_HUB","urlPath":"/group/:groupHubId/manage/:tab?","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"SearchResultsPage","type":"COMMUNITY","urlPath":"/search","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"BlogReplyPage","type":"BLOG_REPLY","urlPath":"/blog/:boardId/:messageSubject/:messageId/replies/:replyId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"GroupHubPage","type":"GROUP_HUB","urlPath":"/group/:groupHubId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"TermsOfServicePage","type":"COMMUNITY","urlPath":"/termsofservice","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"CategoryPage","type":"CATEGORY","urlPath":"/category/:categoryId","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"ForumViewAllTopicsPage","type":"FORUM","urlPath":"/category/:categoryId/discussions/:boardId/all-topics/(/:after|/:before)?","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"TkbPostPage","type":"TKB","urlPath":"/category/:categoryId/kbs/:boardId/create","__typename":"PageDescriptor"},"__typename":"PageResource"},{"lastUpdatedTime":1745487429407,"localOverride":null,"page":{"id":"GroupHubPostPage","type":"GROUP_HUB","urlPath":"/group/:groupHubId/:boardId/create","__typename":"PageDescriptor"},"__typename":"PageResource"}],"localOverride":false},"CachedAsset:text:en_US-components/context/AppContext/AppContextProvider-0":{"__typename":"CachedAsset","id":"text:en_US-components/context/AppContext/AppContextProvider-0","value":{"noCommunity":"Cannot find community","noUser":"Cannot find current user","noNode":"Cannot find node with id {nodeId}","noMessage":"Cannot find message with id {messageId}"},"localOverride":false},"CachedAsset:text:en_US-shared/client/components/common/Loading/LoadingDot-0":{"__typename":"CachedAsset","id":"text:en_US-shared/client/components/common/Loading/LoadingDot-0","value":{"title":"Loading..."},"localOverride":false},"User:user:-1":{"__typename":"User","id":"user:-1","uid":-1,"login":"Deleted","email":"","avatar":null,"rank":null,"kudosWeight":1,"registrationData":{"__typename":"RegistrationData","status":"ANONYMOUS","registrationTime":null,"confirmEmailStatus":false,"registrationAccessLevel":"VIEW","ssoRegistrationFields":[]},"ssoId":null,"profileSettings":{"__typename":"ProfileSettings","dateDisplayStyle":{"__typename":"InheritableStringSettingWithPossibleValues","key":"layout.friendly_dates_enabled","value":"false","localValue":"true","possibleValues":["true","false"]},"dateDisplayFormat":{"__typename":"InheritableStringSetting","key":"layout.format_pattern_date","value":"MMM dd yyyy","localValue":"MM-dd-yyyy"},"language":{"__typename":"InheritableStringSettingWithPossibleValues","key":"profile.language","value":"en-US","localValue":"en","possibleValues":["en-US"]}},"deleted":false},"Theme:customTheme1":{"__typename":"Theme","id":"customTheme1"},"Category:category:microsoft365":{"__typename":"Category","id":"category:microsoft365","entityType":"CATEGORY","displayId":"microsoft365","nodeType":"category","depth":3,"title":"Microsoft 365","shortTitle":"Microsoft 365","parent":{"__ref":"Category:category:products-services"},"categoryPolicies":{"__typename":"CategoryPolicies","canReadNode":{"__typename":"PolicyResult","failureReason":null}}},"Category:category:top":{"__typename":"Category","id":"category:top","displayId":"top","nodeType":"category","depth":0,"title":"Top","entityType":"CATEGORY","shortTitle":"Top"},"Category:category:communities":{"__typename":"Category","id":"category:communities","displayId":"communities","nodeType":"category","depth":1,"parent":{"__ref":"Category:category:top"},"title":"Communities","entityType":"CATEGORY","shortTitle":"Communities"},"Category:category:products-services":{"__typename":"Category","id":"category:products-services","displayId":"products-services","nodeType":"category","depth":2,"parent":{"__ref":"Category:category:communities"},"title":"Products","entityType":"CATEGORY","shortTitle":"Products"},"Forum:board:ExcelGeneral":{"__typename":"Forum","id":"board:ExcelGeneral","entityType":"FORUM","displayId":"ExcelGeneral","nodeType":"board","depth":4,"conversationStyle":"FORUM","title":"Excel","description":"Your community for how-to discussions and sharing best practices on Microsoft Excel. If you’re looking for technical support, please visit Microsoft Support Community.","avatar":null,"profileSettings":{"__typename":"ProfileSettings","language":null},"parent":{"__ref":"Category:category:microsoft365"},"ancestors":{"__typename":"CoreNodeConnection","edges":[{"__typename":"CoreNodeEdge","node":{"__ref":"Community:community:gxcuf89792"}},{"__typename":"CoreNodeEdge","node":{"__ref":"Category:category:communities"}},{"__typename":"CoreNodeEdge","node":{"__ref":"Category:category:products-services"}},{"__typename":"CoreNodeEdge","node":{"__ref":"Category:category:microsoft365"}}]},"userContext":{"__typename":"NodeUserContext","canAddAttachments":false,"canUpdateNode":false,"canPostMessages":false,"isSubscribed":false},"boardPolicies":{"__typename":"BoardPolicies","canPublishArticleOnCreate":{"__typename":"PolicyResult","failureReason":{"__typename":"FailureReason","message":"error.lithium.policies.forums.policy_can_publish_on_create_workflow_action.accessDenied","key":"error.lithium.policies.forums.policy_can_publish_on_create_workflow_action.accessDenied","args":[]}}},"shortTitle":"Excel","repliesProperties":{"__typename":"RepliesProperties","sortOrder":"REVERSE_PUBLISH_TIME","repliesFormat":"threaded"},"tagProperties":{"__typename":"TagNodeProperties","tagsEnabled":{"__typename":"PolicyResult","failureReason":null}},"requireTags":true,"tagType":"PRESET_ONLY","eventPath":"category:microsoft365/category:products-services/category:communities/community:gxcuf89792board:ExcelGeneral/"},"Rank:rank:36":{"__typename":"Rank","id":"rank:36","position":17,"name":"Brass Contributor","color":"333333","icon":null,"rankStyle":"TEXT"},"User:user:1358447":{"__typename":"User","id":"user:1358447","uid":1358447,"login":"Sandeeep","deleted":false,"avatar":{"__typename":"UserAvatar","url":"https://techcommunity.microsoft.com/t5/s/gxcuf89792/images/dS0xMzU4NDQ3LTM5NjYzMGkwQUZGQTYwODQxNEJDMjE2"},"rank":{"__ref":"Rank:rank:36"},"email":"","messagesCount":25,"biography":null,"topicsCount":7,"kudosReceivedCount":1,"kudosGivenCount":1,"kudosWeight":1,"registrationData":{"__typename":"RegistrationData","status":null,"registrationTime":"2022-04-09T05:10:51.119-07:00","confirmEmailStatus":null},"followersCount":null,"solutionsCount":1,"entityType":"USER","eventPath":"community:gxcuf89792/user:1358447"},"ForumTopicMessage:message:3599540":{"__typename":"ForumTopicMessage","uid":3599540,"subject":"VBA: Select multiple Columns till the last row to add a background color.","id":"message:3599540","revisionNum":1,"repliesCount":3,"author":{"__ref":"User:user:1358447"},"depth":0,"hasGivenKudo":false,"board":{"__ref":"Forum:board:ExcelGeneral"},"conversation":{"__ref":"Conversation:conversation:3599540"},"readOnly":false,"editFrozen":false,"moderationData":{"__ref":"ModerationData:moderation_data:3599540"},"body@stripHtml({\"truncateLength\":200})":" VBA code help Select multiple Columns till the last row to add a background color with easy-to-read code. Spent the last 3hrs trying everything I could find on the internet. Problem: I got co...","body@stringLength":"8828","rawBody":"
VBA code help
Select multiple Columns till the last row to add a background color with easy-to-read code.
Spent the last 3hrs trying everything I could find on the internet.
Problem:
I got columns from A:AA, all filled with data (mostly).
Column A will always be filled with an ID, whereas other columns may not.
I'd like to make it all colorful, so it's easier to look at.
Here is an example,
What I need to do is,
So I can make it look like this
Usecase
Select non-consecutive Columns (with no patterns, such as ABC skip EFG skip, etc)
Add a Background color
Finally, for very certain columns, cause there are BLANKS, highlight those that aren't with a different color, and make the text italic.
What is successfully done so far?
Able to get the first set of columns selected and colored via
I'm also adding borders for each colored set of columns, and intended for those columns with TRUE/FALSE to be conditionally formatted, then with borders around each cell.
Range(\"A1\").CurrentRegion.Select\n With Selection\n' On Error Resume Next\n' .SpecialCells(xlCellTypeBlanks).Value = \"0\"\n .BorderAround Weight:=xlMedium\n End With
Use-Case, my Problem: Kinda works (code below)
' Setting User ID Block = Pink Colors\n Range(\"A2:E2\").Resize(Lastrow).Select\n' Range(Selection, Selection.End(xlDown)).Select\n With Selection.Interior\n .Pattern = xlSolid\n .PatternColorIndex = xlAutomatic\n .Color = 14931698\n .TintAndShade = 0\n .PatternTintAndShade = 0\n End With\n \n' Setting Certain column Colors\n Range(\"F2:F2,Y2:Z2\").Select\n Range(Selection, Selection.End(xlDown)).Select\n With Selection.Interior\n .Pattern = xlSolid\n .PatternColorIndex = xlAutomatic\n .ThemeColor = xlThemeColorAccent6\n .TintAndShade = 0.599993896298105\n .PatternTintAndShade = 0\n End With\n\n' Setting Secret Human column Stats Colors\n Range(\"G2:I2\").Select\n Range(Selection, Selection.End(xlDown)).Select\n With Selection.Interior\n .Pattern = xlSolid\n .PatternColorIndex = xlAutomatic\n .ThemeColor = xlThemeColorAccent5\n .TintAndShade = 0.599993896298105\n .PatternTintAndShade = 0\n End With\n With Selection\n' .Borders(xlDiagonalDown).LineStyle = xlNone\n' .Borders(xlDiagonalUp).LineStyle = xlNone\n .Borders.Weight = xlThin\n .Borders(xlInsideVertical).LineStyle = xlNone\n .Borders(xlInsideHorizontal).LineStyle = xlNone\n End With\n \n' Setting TRUE & FALSE CONDITIONAL Colors\n Range(\"J2:K2,O2:S2\").Select\n Range(Selection, Selection.End(xlDown)).Select\n Selection.FormatConditions.Add Type:=xlTextString, String:=\"False\", _\n TextOperator:=xlContains\n Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority\n With Selection.FormatConditions(1).Font\n .Color = -16383844\n .TintAndShade = 0\n End With\n With Selection.FormatConditions(1).Interior\n .PatternColorIndex = xlAutomatic\n .Color = 13551615\n .TintAndShade = 0\n End With\n Selection.FormatConditions(1).StopIfTrue = False\n Selection.FormatConditions.Add Type:=xlTextString, String:=\"True\", _\n TextOperator:=xlContains\n Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority\n With Selection.FormatConditions(1).Font\n .Color = -16752384\n .TintAndShade = 0\n End With\n With Selection.FormatConditions(1).Interior\n .PatternColorIndex = xlAutomatic\n .Color = 13561798\n .TintAndShade = 0\n End With\n Selection.FormatConditions(1).StopIfTrue = False\n
Notes
Yes, I know there are comments on my code, that would be me trying various things and failing for the past 3hrs.
I tried For Each loop, the array needs to be defined previously. Given I have so many ranges, this will end up with 10-15 ranges that'll just be used once in the code and feel very redundant.
I've also tried to get the last row, via a variable and count. Then attempt to truncate that to the selection range formulas with no success.
Brute force manual code for each task does work but ends up being 500+ lines of code, and I'd love to reduce it all.
Example's Data (shown in the Pic above, so you can copy-paste it)
ID
Status
EventHappen
Reason
Gone?
Total Time
Name
1001
CLOSED
TRUE
he ran
FALSE
0.000416667
Jack
1002
CLOSED
FALSE
FALSE
0.000219907
Davis
1003
CLOSED
FALSE
FALSE
0.001863426
Drew
1004
CLOSED
FALSE
TRUE
0.000208333
Kumar
1005
CLOSED
FALSE
FALSE
0.000150463
Kiran
1006
CLOSED
FALSE
FALSE
0.027916667
Allysa
1007
CLOSED
FALSE
FALSE
0.003148148
Tom
1008
CLOSED
FALSE
FALSE
0.006643519
Brady
1009
CLOSED
FALSE
FALSE
3.47222E-05
Brandon
1010
CLOSED
TRUE
she jumped
FALSE
0.001134259
Joe
1011
CLOSED
FALSE
FALSE
0.000613426
Jack
1012
CLOSED
FALSE
FALSE
0.006851852
Jacky
1013
CLOSED
FALSE
FALSE
0.004363426
William
1014
CLOSED
FALSE
FALSE
0.003969907
Selena
1015
CLOSED
TRUE
they swam
FALSE
0.002268519
Joesph
1016
CLOSED
TRUE
I don’t know
FALSE
0.000914352
Joesph
Please do assist. Thank you!
","kudosSumWeight":0,"postTime":"2022-08-14T15:29:16.832-07:00","images":{"__typename":"AssociatedImageConnection","edges":[{"__typename":"AssociatedImageEdge","cursor":"MjUuMXwyLjF8b3wyNXxfTlZffDE","node":{"__ref":"AssociatedImage:{\"url\":\"https://techcommunity.microsoft.com/t5/s/gxcuf89792/images/bS0zNTk5NTQwLTM5NTc5NGkxMzI1MUVEOTAwNEIxMEYz?revision=1\"}"}},{"__typename":"AssociatedImageEdge","cursor":"MjUuMXwyLjF8b3wyNXxfTlZffDI","node":{"__ref":"AssociatedImage:{\"url\":\"https://techcommunity.microsoft.com/t5/s/gxcuf89792/images/bS0zNTk5NTQwLTM5NTc5NWlGMzA1NjBBRTM4QjE5QjNF?revision=1\"}"}},{"__typename":"AssociatedImageEdge","cursor":"MjUuMXwyLjF8b3wyNXxfTlZffDM","node":{"__ref":"AssociatedImage:{\"url\":\"https://techcommunity.microsoft.com/t5/s/gxcuf89792/images/bS0zNTk5NTQwLTM5NTc5Nmk1NjI5Rjc2N0FFM0RDQTZF?revision=1\"}"}}],"totalCount":3,"pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null}},"attachments":{"__typename":"AttachmentConnection","pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null},"edges":[]},"tags":{"__typename":"TagConnection","pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null},"edges":[{"__typename":"TagEdge","cursor":"MjUuMXwyLjF8b3wxMHxfTlZffDE","node":{"__typename":"Tag","id":"tag:excel","text":"excel","time":"2016-06-21T14:08:51.129-07:00","lastActivityTime":null,"messagesCount":null,"followersCount":null}},{"__typename":"TagEdge","cursor":"MjUuMXwyLjF8b3wxMHxfTlZffDI","node":{"__typename":"Tag","id":"tag:Macros and VBA","text":"Macros and VBA","time":"2016-06-24T14:00:56.974-07:00","lastActivityTime":null,"messagesCount":null,"followersCount":null}}]},"timeToRead":3,"currentRevision":{"__ref":"Revision:revision:3599540_1"},"latestVersion":null,"metrics":{"__typename":"MessageMetrics","views":7929},"visibilityScope":"PUBLIC","canonicalUrl":null,"seoTitle":null,"seoDescription":null,"isEscalated":null,"placeholder":false,"originalMessageForPlaceholder":null,"messagePolicies":{"__typename":"MessagePolicies","canModerateSpamMessage":{"__typename":"PolicyResult","failureReason":{"__typename":"FailureReason","message":"error.lithium.policies.feature.moderation_spam.action.moderate_entity.allowed.accessDenied","key":"error.lithium.policies.feature.moderation_spam.action.moderate_entity.allowed.accessDenied","args":[]}}},"archivalData":null,"customFields":[],"body":"
VBA code help
Select multiple Columns till the last row to add a background color with easy-to-read code.
Spent the last 3hrs trying everything I could find on the internet.
Problem:
I got columns from A:AA, all filled with data (mostly).
Column A will always be filled with an ID, whereas other columns may not.
I'd like to make it all colorful, so it's easier to look at.
Here is an example,
What I need to do is,
So I can make it look like this
Usecase
Select non-consecutive Columns (with no patterns, such as ABC skip EFG skip, etc)
Add a Background color
Finally, for very certain columns, cause there are BLANKS, highlight those that aren't with a different color, and make the text italic.
What is successfully done so far?
Able to get the first set of columns selected and colored via
I'm also adding borders for each colored set of columns, and intended for those columns with TRUE/FALSE to be conditionally formatted, then with borders around each cell.
Range(\"A1\").CurrentRegion.Select\n With Selection\n' On Error Resume Next\n' .SpecialCells(xlCellTypeBlanks).Value = \"0\"\n .BorderAround Weight:=xlMedium\n End With
Use-Case, my Problem: Kinda works (code below)
' Setting User ID Block = Pink Colors\n Range(\"A2:E2\").Resize(Lastrow).Select\n' Range(Selection, Selection.End(xlDown)).Select\n With Selection.Interior\n .Pattern = xlSolid\n .PatternColorIndex = xlAutomatic\n .Color = 14931698\n .TintAndShade = 0\n .PatternTintAndShade = 0\n End With\n \n' Setting Certain column Colors\n Range(\"F2:F2,Y2:Z2\").Select\n Range(Selection, Selection.End(xlDown)).Select\n With Selection.Interior\n .Pattern = xlSolid\n .PatternColorIndex = xlAutomatic\n .ThemeColor = xlThemeColorAccent6\n .TintAndShade = 0.599993896298105\n .PatternTintAndShade = 0\n End With\n\n' Setting Secret Human column Stats Colors\n Range(\"G2:I2\").Select\n Range(Selection, Selection.End(xlDown)).Select\n With Selection.Interior\n .Pattern = xlSolid\n .PatternColorIndex = xlAutomatic\n .ThemeColor = xlThemeColorAccent5\n .TintAndShade = 0.599993896298105\n .PatternTintAndShade = 0\n End With\n With Selection\n' .Borders(xlDiagonalDown).LineStyle = xlNone\n' .Borders(xlDiagonalUp).LineStyle = xlNone\n .Borders.Weight = xlThin\n .Borders(xlInsideVertical).LineStyle = xlNone\n .Borders(xlInsideHorizontal).LineStyle = xlNone\n End With\n \n' Setting TRUE & FALSE CONDITIONAL Colors\n Range(\"J2:K2,O2:S2\").Select\n Range(Selection, Selection.End(xlDown)).Select\n Selection.FormatConditions.Add Type:=xlTextString, String:=\"False\", _\n TextOperator:=xlContains\n Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority\n With Selection.FormatConditions(1).Font\n .Color = -16383844\n .TintAndShade = 0\n End With\n With Selection.FormatConditions(1).Interior\n .PatternColorIndex = xlAutomatic\n .Color = 13551615\n .TintAndShade = 0\n End With\n Selection.FormatConditions(1).StopIfTrue = False\n Selection.FormatConditions.Add Type:=xlTextString, String:=\"True\", _\n TextOperator:=xlContains\n Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority\n With Selection.FormatConditions(1).Font\n .Color = -16752384\n .TintAndShade = 0\n End With\n With Selection.FormatConditions(1).Interior\n .PatternColorIndex = xlAutomatic\n .Color = 13561798\n .TintAndShade = 0\n End With\n Selection.FormatConditions(1).StopIfTrue = False\n
Notes
Yes, I know there are comments on my code, that would be me trying various things and failing for the past 3hrs.
I tried For Each loop, the array needs to be defined previously. Given I have so many ranges, this will end up with 10-15 ranges that'll just be used once in the code and feel very redundant.
I've also tried to get the last row, via a variable and count. Then attempt to truncate that to the selection range formulas with no success.
Brute force manual code for each task does work but ends up being 500+ lines of code, and I'd love to reduce it all.
Example's Data (shown in the Pic above, so you can copy-paste it)
ID
Status
EventHappen
Reason
Gone?
Total Time
Name
1001
CLOSED
TRUE
he ran
FALSE
0.000416667
Jack
1002
CLOSED
FALSE
FALSE
0.000219907
Davis
1003
CLOSED
FALSE
FALSE
0.001863426
Drew
1004
CLOSED
FALSE
TRUE
0.000208333
Kumar
1005
CLOSED
FALSE
FALSE
0.000150463
Kiran
1006
CLOSED
FALSE
FALSE
0.027916667
Allysa
1007
CLOSED
FALSE
FALSE
0.003148148
Tom
1008
CLOSED
FALSE
FALSE
0.006643519
Brady
1009
CLOSED
FALSE
FALSE
3.47222E-05
Brandon
1010
CLOSED
TRUE
she jumped
FALSE
0.001134259
Joe
1011
CLOSED
FALSE
FALSE
0.000613426
Jack
1012
CLOSED
FALSE
FALSE
0.006851852
Jacky
1013
CLOSED
FALSE
FALSE
0.004363426
William
1014
CLOSED
FALSE
FALSE
0.003969907
Selena
1015
CLOSED
TRUE
they swam
FALSE
0.002268519
Joesph
1016
CLOSED
TRUE
I don’t know
FALSE
0.000914352
Joesph
Please do assist. Thank you!
"},"Conversation:conversation:3599540":{"__typename":"Conversation","id":"conversation:3599540","solved":true,"topic":{"__ref":"ForumTopicMessage:message:3599540"},"lastPostingActivityTime":"2022-08-15T10:27:24.784-07:00","lastPostTime":"2022-08-15T10:27:24.784-07:00","unreadReplyCount":3,"isSubscribed":false},"ModerationData:moderation_data:3599540":{"__typename":"ModerationData","id":"moderation_data:3599540","status":"APPROVED","rejectReason":null,"isReportedAbuse":false,"rejectUser":null,"rejectTime":null,"rejectActorType":null},"AssociatedImage:{\"url\":\"https://techcommunity.microsoft.com/t5/s/gxcuf89792/images/bS0zNTk5NTQwLTM5NTc5NGkxMzI1MUVEOTAwNEIxMEYz?revision=1\"}":{"__typename":"AssociatedImage","url":"https://techcommunity.microsoft.com/t5/s/gxcuf89792/images/bS0zNTk5NTQwLTM5NTc5NGkxMzI1MUVEOTAwNEIxMEYz?revision=1","title":"Sandeeep_1-1660514748279.png","associationType":"BODY","width":625,"height":442,"altText":null},"AssociatedImage:{\"url\":\"https://techcommunity.microsoft.com/t5/s/gxcuf89792/images/bS0zNTk5NTQwLTM5NTc5NWlGMzA1NjBBRTM4QjE5QjNF?revision=1\"}":{"__typename":"AssociatedImage","url":"https://techcommunity.microsoft.com/t5/s/gxcuf89792/images/bS0zNTk5NTQwLTM5NTc5NWlGMzA1NjBBRTM4QjE5QjNF?revision=1","title":"Sandeeep_2-1660514776037.png","associationType":"BODY","width":633,"height":454,"altText":null},"AssociatedImage:{\"url\":\"https://techcommunity.microsoft.com/t5/s/gxcuf89792/images/bS0zNTk5NTQwLTM5NTc5Nmk1NjI5Rjc2N0FFM0RDQTZF?revision=1\"}":{"__typename":"AssociatedImage","url":"https://techcommunity.microsoft.com/t5/s/gxcuf89792/images/bS0zNTk5NTQwLTM5NTc5Nmk1NjI5Rjc2N0FFM0RDQTZF?revision=1","title":"Sandeeep_3-1660514826382.png","associationType":"BODY","width":634,"height":460,"altText":null},"Revision:revision:3599540_1":{"__typename":"Revision","id":"revision:3599540_1","lastEditTime":"2022-08-14T15:29:16.832-07:00"},"ForumReplyMessage:message:3599756":{"__typename":"ForumReplyMessage","id":"message:3599756","conversation":{"__ref":"Conversation:conversation:3599540"},"author":{"__ref":"User:user:722750"},"revisionNum":1,"uid":3599756,"depth":1,"hasGivenKudo":false,"subscribed":false,"board":{"__ref":"Forum:board:ExcelGeneral"},"subject":"Re: VBA: Select multiple Columns till the last row to add a background color.","readOnly":false,"editFrozen":false,"moderationData":{"__ref":"ModerationData:moderation_data:3599756"},"parent":{"__ref":"ForumTopicMessage:message:3599540"},"body":"
Yep, needs to be VBA. The point is to beautify my data.
I get 5 excel files, every day in the same fashion. excepts values are different. Row count ranging from 15-15k
I just want them to all look nicer, and have my eyes dart/go to where it's immediately needed. And I don't wanna keep doing conditional formatting 27 columns 5-7 times a day 25 days a month, with multiple clicks or spend lots of time. Just one quick macro and I'm done.
Btw, can you help me with the condition formatting of column D, labeled 'REASON'. I need for the selection to identify if the cell is empty or not. If it is not empty, then change the formatting (BGcolor and font)
I tried using a IF THEN, for each. with ISEMPTY and ISTEXT. it doesn't seem to do it.
As for all the other questions, I guess if it's too complex, I'll copy-paste the same code for each colored blocks. (makes the code twice as long, but at least it works)
Here is the code, I currently have, that applies a BG color to the selected range, but again doesn't apply a different formatting to Non-Empty cells in the same selected range.
Range(\"L2:M2\").Resize(Lastrow).Select ' Where Lastrow is the last populated row in ColA\n With Selection.Interior ' BG color all the selected cells\n .Pattern = xlSolid\n .PatternColorIndex = xlAutomatic\n .ThemeColor = xlThemeColorAccent4\n .TintAndShade = 0.599993896298105\n .PatternTintAndShade = 0\n End With\n\n' The if statement to find which of the cells in the range is Non-Empty and add \n' different formatting, i.e making it gold and italic\n With Selection\n If IsEmpty(Selection.Value) = True Then\n .Font.Italic = True\n .Pattern = xlSolid\n .PatternColorIndex = xlAutomatic\n .ThemeColor = xlThemeColorAccent4\n .TintAndShade = 0.399975585192419\n .PatternTintAndShade = 0\n End If\n End With\n' Adding Borders to this selection \nWith Selection ' Adding Borders\n .Borders.Weight = xlThin\n .Borders(xlInsideVertical).LineStyle = xlNone\n .Borders(xlInsideHorizontal).LineStyle = xlNone\n End With
","body@stripHtml({\"removeProcessingText\":false,\"removeSpoilerMarkup\":false,\"removeTocMarkup\":false,\"truncateLength\":200})@stringLength":"218","kudosSumWeight":0,"postTime":"2022-08-15T09:59:07.816-07:00","lastPublishTime":"2022-08-15T09:59:07.816-07:00","metrics":{"__typename":"MessageMetrics","views":7538},"visibilityScope":"PUBLIC","placeholder":false,"originalMessageForPlaceholder":null,"isEscalated":null,"solution":false,"entityType":"FORUM_REPLY","eventPath":"category:microsoft365/category:products-services/category:communities/community:gxcuf89792board:ExcelGeneral/message:3599540/message:3600124","replies":{"__typename":"MessageConnection","pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null},"edges":[{"__typename":"MessageEdge","cursor":"MjUuMXwyLjF8aXwzfDEzMjowfGludCwzNjAwMTQ3LDM2MDAxNDc","node":{"__ref":"AcceptedSolutionMessage:message:3600147"}}]},"customFields":[],"attachments":{"__typename":"AttachmentConnection","edges":[],"pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null}}},"ModerationData:moderation_data:3600147":{"__typename":"ModerationData","id":"moderation_data:3600147","status":"APPROVED","rejectReason":null,"isReportedAbuse":false,"rejectUser":null,"rejectTime":null,"rejectActorType":null},"AssociatedImage:{\"url\":\"https://techcommunity.microsoft.com/t5/s/gxcuf89792/images/bS0zNjAwMTQ3LTM5NTk3NGk3QzkxQTJGMTY0NkZDNjBD?revision=1\"}":{"__typename":"AssociatedImage","url":"https://techcommunity.microsoft.com/t5/s/gxcuf89792/images/bS0zNjAwMTQ3LTM5NTk3NGk3QzkxQTJGMTY0NkZDNjBD?revision=1","title":"Sandeeep_0-1660584419830.png","associationType":"BODY","width":1498,"height":723,"altText":null},"AcceptedSolutionMessage:message:3600147":{"__typename":"AcceptedSolutionMessage","author":{"__ref":"User:user:1358447"},"id":"message:3600147","revisionNum":1,"uid":3600147,"depth":3,"hasGivenKudo":false,"subscribed":false,"board":{"__ref":"Forum:board:ExcelGeneral"},"parent":{"__ref":"ForumReplyMessage:message:3600124"},"conversation":{"__ref":"Conversation:conversation:3599540"},"subject":"Re: VBA: Select multiple Columns till the last row to add a background color.","moderationData":{"__ref":"ModerationData:moderation_data:3600147"},"body":"
For Each TextCell In Selection\n If TextCell <> \"\" Then\n TextCell.Font.Italic = True\n TextCell.Interior.Pattern = xlSolid\n TextCell.Interior.PatternColorIndex = xlAutomatic\n TextCell.Interior.ThemeColor = xlThemeColorAccent4\n TextCell.Interior.TintAndShade = 0.399975585192419\n TextCell.Interior.PatternTintAndShade = 0\n End If\n Next
","body@stripHtml({\"removeProcessingText\":true,\"removeSpoilerMarkup\":true,\"removeTocMarkup\":true,\"truncateLength\":200})@stringLength":"214","postTime":"2022-08-15T10:27:24.784-07:00","lastPublishTime":"2022-08-15T10:27:24.784-07:00","images":{"__typename":"AssociatedImageConnection","edges":[{"__typename":"AssociatedImageEdge","cursor":"MjUuMXwyLjF8b3wyNXxfTlZffDE","node":{"__ref":"AssociatedImage:{\"url\":\"https://techcommunity.microsoft.com/t5/s/gxcuf89792/images/bS0zNjAwMTQ3LTM5NTk3NGk3QzkxQTJGMTY0NkZDNjBD?revision=1\"}"}}],"totalCount":1,"pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null}},"attachments":{"__typename":"AttachmentConnection","pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null},"edges":[]},"solution":true,"metrics":{"__typename":"MessageMetrics","views":7669},"placeholder":false,"originalMessageForPlaceholder":null,"videos":{"__typename":"VideoConnection","edges":[],"totalCount":0,"pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null}},"isEscalated":null,"entityType":"FORUM_REPLY","eventPath":"category:microsoft365/category:products-services/category:communities/community:gxcuf89792board:ExcelGeneral/message:3599540/message:3600147","customFields":[],"body@stripHtml({\"removeProcessingText\":false,\"removeSpoilerMarkup\":false,\"removeTocMarkup\":false,\"truncateLength\":200})@stringLength":"214","kudosSumWeight":0,"repliesCount":0,"visibilityScope":"PUBLIC","replies":{"__typename":"MessageConnection","pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null},"edges":[]}},"Rank:rank:31":{"__typename":"Rank","id":"rank:31","position":12,"name":"Gold Contributor","color":"333333","icon":null,"rankStyle":"TEXT"},"User:user:722750":{"__typename":"User","id":"user:722750","uid":722750,"login":"NikolinoDE","deleted":false,"avatar":{"__typename":"UserAvatar","url":"https://techcommunity.microsoft.com/t5/s/gxcuf89792/images/dS03MjI3NTAtMjU2NTAwaTlFOUZGMTI1OUEyRjU4OTc"},"rank":{"__ref":"Rank:rank:31"},"email":"","messagesCount":7416,"biography":null,"topicsCount":19,"kudosReceivedCount":1198,"kudosGivenCount":233,"kudosWeight":1,"registrationData":{"__typename":"RegistrationData","status":null,"registrationTime":"2020-07-08T12:46:57.742-07:00","confirmEmailStatus":null},"followersCount":null,"solutionsCount":529},"ModerationData:moderation_data:3599756":{"__typename":"ModerationData","id":"moderation_data:3599756","status":"APPROVED","rejectReason":null,"isReportedAbuse":false,"rejectUser":null,"rejectTime":null,"rejectActorType":null},"Attachment:{\"id\":\"attachment:message3599756AttachmentNumber1\",\"url\":\"https://techcommunity.microsoft.com/t5/s/gxcuf89792/attachments/gxcuf89792/ExcelGeneral/158896/1/Colour_coloumns_and_last_row.xlsm\"}":{"__typename":"Attachment","id":"attachment:message3599756AttachmentNumber1","filename":"Colour_coloumns_and_last_row.xlsm","filesize":23745,"contentType":"application/vnd.ms-excel.sheet.macroEnabled.12","url":"https://techcommunity.microsoft.com/t5/s/gxcuf89792/attachments/gxcuf89792/ExcelGeneral/158896/1/Colour_coloumns_and_last_row.xlsm"},"Revision:revision:3599756_1":{"__typename":"Revision","id":"revision:3599756_1","lastEditTime":"2022-08-15T01:22:13.715-07:00"},"QueryVariables:ReplyList:message:3599756:1":{"__typename":"QueryVariables","id":"ReplyList:message:3599756:1","value":{"id":"message:3599756","first":10,"sorts":{"postTime":{"direction":"DESC"}},"repliesFirst":3,"repliesFirstDepthThree":1,"repliesSorts":{"postTime":{"direction":"DESC"}},"useAvatar":true,"useAuthorLogin":true,"useAuthorRank":true,"useBody":true,"useKudosCount":true,"useTimeToRead":false,"useMedia":false,"useReadOnlyIcon":false,"useRepliesCount":true,"useSearchSnippet":false,"useAcceptedSolutionButton":true,"useSolvedBadge":false,"useAttachments":false,"attachmentsFirst":5,"useTags":false,"useNodeAncestors":false,"useUserHoverCard":false,"useNodeHoverCard":false,"useModerationStatus":true,"usePreviewSubjectModal":false,"useMessageStatus":true}},"CachedAsset:text:en_US-shared/client/components/users/UserAvatar-1745505309806":{"__typename":"CachedAsset","id":"text:en_US-shared/client/components/users/UserAvatar-1745505309806","value":{"altText":"{login}'s avatar","altTextGeneric":"User's avatar"},"localOverride":false},"CachedAsset:text:en_US-shared/client/components/ranks/UserRankLabel-1745505309806":{"__typename":"CachedAsset","id":"text:en_US-shared/client/components/ranks/UserRankLabel-1745505309806","value":{"altTitle":"Icon for {rankName} rank"},"localOverride":false},"CachedAsset:text:en_US-components/messages/AcceptedSolutionButton-1745505309806":{"__typename":"CachedAsset","id":"text:en_US-components/messages/AcceptedSolutionButton-1745505309806","value":{"accept":"Mark as Solution","accepted":"Marked as Solution","errorHeader":"Error!","errorAdd":"There was an error marking as solution.","errorRemove":"There was an error unmarking as solution.","solved":"Solved"},"localOverride":false},"CachedAsset:text:en_US-components/messages/ThreadedReplyList-1745505309806":{"__typename":"CachedAsset","id":"text:en_US-components/messages/ThreadedReplyList-1745505309806","value":{"title":"{count, plural, one{# Reply} other{# Replies}}","title@board:BLOG":"{count, plural, one{# Comment} other{# Comments}}","title@board:TKB":"{count, plural, one{# Comment} other{# Comments}}","title@board:IDEA":"{count, plural, one{# Comment} other{# Comments}}","title@board:OCCASION":"{count, plural, one{# Comment} other{# Comments}}","noRepliesTitle":"No Replies","noRepliesTitle@board:BLOG":"No Comments","noRepliesTitle@board:TKB":"No Comments","noRepliesTitle@board:IDEA":"No Comments","noRepliesTitle@board:OCCASION":"No Comments","noRepliesDescription":"Be the first to reply","noRepliesDescription@board:BLOG":"Be the first to comment","noRepliesDescription@board:TKB":"Be the first to comment","noRepliesDescription@board:IDEA":"Be the first to comment","noRepliesDescription@board:OCCASION":"Be the first to comment","messageReadOnlyAlert:BLOG":"Comments have been turned off for this post","messageReadOnlyAlert:TKB":"Comments have been turned off for this article","messageReadOnlyAlert:IDEA":"Comments have been turned off for this idea","messageReadOnlyAlert:FORUM":"Replies have been turned off for this discussion","messageReadOnlyAlert:OCCASION":"Comments have been turned off for this event"},"localOverride":false},"ModerationData:moderation_data:3600124":{"__typename":"ModerationData","id":"moderation_data:3600124","status":"APPROVED","rejectReason":null,"isReportedAbuse":false,"rejectUser":null,"rejectTime":null,"rejectActorType":null},"CachedAsset:text:en_US-components/tags/TagView/TagViewChip-1745505309806":{"__typename":"CachedAsset","id":"text:en_US-components/tags/TagView/TagViewChip-1745505309806","value":{"tagLabelName":"Tag name {tagName}"},"localOverride":false},"CachedAsset:text:en_US-components/attachments/AttachmentView/AttachmentViewChip-1745505309806":{"__typename":"CachedAsset","id":"text:en_US-components/attachments/AttachmentView/AttachmentViewChip-1745505309806","value":{"errorTitle":"Failed!","previewFile":"Preview File","downloadFile":"Download File {name}","removeFile":"Remove File {name}","errorBadExtension":"This file does not have a valid extension. \"{extensions}\" are the valid extensions.","errorFileEmpty":"This file is empty or does not exist.","errorTooLarge":"The maximum file size is: {maxFileSize}.","errorTooMany":"Too many attachments. The maximum number of attachments per message is: {maxAttachmentCount, number, integer}.","errorDuplicate":"This file is already attached."},"localOverride":false},"CachedAsset:text:en_US-shared/client/components/common/Pager/PagerLoadMore-1745505309806":{"__typename":"CachedAsset","id":"text:en_US-shared/client/components/common/Pager/PagerLoadMore-1745505309806","value":{"loadMore":"Show More"},"localOverride":false}}}},"page":"/forums/ForumMessagePage/ForumMessagePage","query":{"boardId":"excelgeneral","messageSubject":"vba-select-multiple-columns-till-the-last-row-to-add-a-background-color-","messageId":"3599540","replyId":"3599756"},"buildId":"HEhyUrv5OXNBIbfCLaOrw","runtimeConfig":{"buildInformationVisible":false,"logLevelApp":"info","logLevelMetrics":"info","openTelemetryClientEnabled":false,"openTelemetryConfigName":"o365","openTelemetryServiceVersion":"25.1.0","openTelemetryUniverse":"prod","openTelemetryCollector":"http://localhost:4318","openTelemetryRouteChangeAllowedTime":"5000","apolloDevToolsEnabled":false,"inboxMuteWipFeatureEnabled":false},"isFallback":false,"isExperimentalCompile":false,"dynamicIds":["./components/seo/QAPageSchema/QAPageSchema.tsx","./components/community/Navbar/NavbarWidget.tsx","./components/community/Breadcrumb/BreadcrumbWidget.tsx","./components/customComponent/CustomComponent/CustomComponent.tsx","./components/messages/TopicWithThreadedReplyListWidget/TopicWithThreadedReplyListWidget.tsx","./components/external/components/ExternalComponent.tsx","./components/messages/MessageView/MessageViewStandard/MessageViewStandard.tsx","../shared/client/components/common/List/UnstyledList/UnstyledList.tsx","./components/messages/MessageView/MessageView.tsx","../shared/client/components/common/List/UnwrappedList/UnwrappedList.tsx","./components/tags/TagView/TagView.tsx","./components/tags/TagView/TagViewChip/TagViewChip.tsx","./components/attachments/AttachmentView/AttachmentView.tsx","./components/attachments/AttachmentView/AttachmentViewChip/AttachmentViewChip.tsx","../shared/client/components/common/Pager/PagerLoadMore/PagerLoadMore.tsx"],"appGip":true,"scriptLoader":[{"id":"analytics","src":"https://techcommunity.microsoft.com/t5/s/gxcuf89792/pagescripts/1730819800000/analytics.js?page.id=ForumReplyPage&entity.id=board%3Aexcelgeneral&entity.id=message%3A3599756","strategy":"afterInteractive"}]}