Skip to content

Include type = "custom" for wb_add_data_validation() #1264

Answered by JanMarvin
johngodlee asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @johngodlee ,

I'm not that big in data validation, but the following should be what you want (we actually support type custom, but only in a few examples hidden in our test files). Be aware that we do not check the formula for valid XML, hence you have to escape & as &.

library(openxlsx2)

vals <- c("A", "B", "C", "AB", "ABC", "G", "AG")

lups <- c("A", "B", "C")

wb <- wb_workbook()$add_worksheet()$
  add_data(x = vals, dims = wb_dims(x = vals))$
  add_data(x = lups, dims = wb_dims(x = lups, from_col = "C"))$
  add_data_validation(type = "custom", dims = "A1:A7", 
                      value = 'SUMPRODUCT(--ISNUMBER(MATCH(MID(A1,ROW(INDIRECT("1:"&amp;LEN(A1))),1), C$1:C$3, 0))) = …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@johngodlee
Comment options

@JanMarvin
Comment options

Answer selected by johngodlee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1263 on February 11, 2025 18:31.